473,399 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

If/Then help!

16
I have a form that I want to automatically fill in information on.

When the LeaseNumber field is equal to the PrevLeaseNumber field, I want to fill in LeaseName and Location with DLookup or some other action that would retrieve them from the previous record.

Should I use a macro? SQL? An OnUpdate event?
Oct 20 '06 #1
4 3023
MMcCarthy
14,534 Expert Mod 8TB
In the After Update event of the LeaseNumber field control.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Sub LeaseNumber_AfterUpdate()
  3.  
  4.   If Me.LeaseNumber = Me.PrevLeaseNumber Then
  5.     Me.LeaseName = Dlookup("[LeaseName]","TableName","[LeaseNumber]=" & Me.LeaseNumber)
  6.     Me.Location = Dlookup("[Location]","TableName","[LeaseNumber]=" & Me.LeaseNumber)
  7.   End If
  8.  
  9. End Sub
  10.  
  11.  
or if LeaseNumber is a text field then:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Sub LeaseNumber_AfterUpdate()
  3.  
  4.   If Me.LeaseNumber = Me.PrevLeaseNumber Then
  5.     Me.LeaseName = Dlookup("[LeaseName]","TableName","[LeaseNumber]='" & Me.LeaseNumber & "'")
  6.     Me.Location = Dlookup("[Location]","TableName","[LeaseNumber'" & Me.LeaseNumber & "'")
  7.   End If
  8.  
  9. End Sub
  10.  
  11.  
Oct 20 '06 #2
KelHemp
16
In the After Update event of the LeaseNumber field control.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Sub LeaseNumber_AfterUpdate()
  3.  
  4.   If Me.LeaseNumber = Me.PrevLeaseNumber Then
  5.     Me.LeaseName = Dlookup("[LeaseName]","TableName","[LeaseNumber]=" & Me.LeaseNumber)
  6.     Me.Location = Dlookup("[Location]","TableName","[LeaseNumber]=" & Me.LeaseNumber)
  7.   End If
  8.  
  9. End Sub
It is a number type. I went into the AfterUpdate and pasted the code, but nothing happened like I wanted. I hit the "Code Bulder" option and it automatically created the lines
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Public Sub Lease_Number_AfterUpdate()
  3.  
  4. End Sub
  5.  
And I pasted the middle section in and tried that.

Now, it gives me a compile error: Method or data member not found.
It also highlights the "Public Sub..." line. it selects the ".LeaseNumber" bit too.
Oct 20 '06 #3
KelHemp
16
okay, I'm an idiot. I forgot to replace "TableName" with the name of my table, Products1. And I replaced the "." in each line with "!" and it works great now.

Thanks for the help!
Here's what I ended up with:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Public Sub Lease_Number_AfterUpdate()
  3.  
  4. If Me!LeaseNumber = Me!PrevLeaseNumber Then
  5.     Me!LeaseName = DLookup("[LeaseName]", "Products1", "[LeaseNumber]=" & Me!LeaseNumber)
  6.     Me!Location = DLookup("[Location]", "Products1", "[LeaseNumber]=" & Me!LeaseNumber)
  7.   End If
  8.  
  9. End Sub
Oct 20 '06 #4
MMcCarthy
14,534 Expert Mod 8TB
LeaseNumber is Lease_Number on the form.

Public Sub Lease_Number_AfterUpdate()

If Me.Lease_Number = Me.PrevLeaseNumber Then
Me.LeaseName = Dlookup("[LeaseName]","TableName","[LeaseNumber]=" & Me.Lease_Number)
Me.Location = Dlookup("[Location]","TableName","[LeaseNumber]=" & Me.Lease_Number)
End If

End Sub
Oct 20 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Bob | last post by:
ok i have a program tah randomizes number adn signs (+,-). i made it so little kids can learn math easily and i wouldn't have to write each question out. when the plus sign is used, eveyrthing...
17
by: shank | last post by:
I'm coming from the ASP worl and have no clue to javascript. In the following code, I'm trying to set the value for variable strPage, then use that in the redirect statement. The page does nothing....
3
by: mallyonline | last post by:
I last posted to this group about 6 months ago and was very pleased by the excellent response I got and the great help offered to me. I am back this time with another request for your expert help...
3
by: Prakash Wadhwani | last post by:
Hi !! I have been browsing around but have not been able to find a simple, lucid solution ... or maybe I'm just too confused. I know this has been asked before by many ... but pls bear with me. ...
2
by: misscrf | last post by:
I have a search form that is great. I have modified it in such a way, that when search results come up I can bring it back to a useful spot, say an entry form or a report. Here is my lemon (...
4
by: louise raisbeck | last post by:
I have this scenario (simplified) function addnewdata () { check for partial match already in db for information entered by user if (partialmatch succeeds) { open new window aspx page (using...
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
3
by: Knick via AccessMonster.com | last post by:
I am novice to MS Access Development, I regularly back my access database every 2, 3 days ...today when I was going to back my database I saw the access file on the network drive was only 9 MB...
4
by: Vernon Wenberg III | last post by:
I'm not really sure how readline() works. Is there a way to iterate through a file with multiple lines and then putting each line in a variable in a loop?
15
by: jzakiya | last post by:
I'm translating a program in Python that has this IF Then chain IF x1 < limit: --- do a --- IF x2 < limit: --- do b --- IF x3 < limit: --- do c --- .----- ------ IF x10 < limt: ---...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.