DLookup in VBA

Badeye

Registered User.
Local time
Today, 20:59
Joined
Oct 14, 2011
Messages
22
Hi Guys,

I have a user form with 2 textboxes. the first is to enter a 5 digit site code and the second is for the sitename. What i am trying to do is in the afterupdate of the first textbox in VBA is do a DLookup to pull through the site name from the sites table and populate the second textbox.

My textboxes are named
1st textbox = nscode
2nd textbox = nsitename

my DLookup looks like this.

Code:
Me.nsitename.Value = DLookup("[Site Name]", "Sites", [SiteCode] = Me.nscode)
Now it appears to kind of work but its not looking at the criteria and its just pulling through a random site name rather that the one i want.

Any help would be greatly appreciated.

Si
 
Even the criteria should be placed inside doubl quotes.. so it should be something like..
Code:
Me.nsitename.Value = DLookup("[Site Name]", "Sites", "[SiteCode] = '" & Me.nscode & "'")

Use the single qoues only if it a string.. else it should be something like this,
Code:
Me.nsitename.Value = DLookup("[Site Name]", "Sites", "[SiteCode] = " & Me.nscode & "")
 
Thanks so much, thats works a treat. I get a little confused with the criteria and the quotes.

Si
 
Awesome, you guys helped me with this issue as well. Search featured helped as intended!
 

Users who are viewing this thread

Back
Top Bottom