Problem with DLookup - Can anyone see why this isnt working?

shabbaranks

Registered User.
Local time
Today, 03:34
Joined
Oct 17, 2011
Messages
300
Hi Guys,

Ive got a DLookup within my VBA code and I cant for the life of me see why its not refererncing the correct field and returning the right result. As from the screen grab if I use the immediate window to query the variable its not whats in the table

http://i.imgur.com/EZ4bZ.jpg

Any ideas?

Thanks
 
Well since your variable sUserID is defined as String you must enclose it in quotes.

sGroupID= Dlookup("DepGroupID", "UserNames_tbl", "[sUser]= '" & sUserID & "'")

JR
 
Thanks for that, unfortunatly the sGroupID value returned is still 0 when it should be 3 :confused:
 
It looks like you might be confusing your primary key with the username field. Is sUserID the string or the autonumber? Rather, does me.currentUser = 27 or "simon.schuck"?
 
me.currentuser = simon.schuck although if it was confusing it wouldnt the return value be 27 rather than 0?

Thanks
 
Have you used any lookups in your tables? Specifically, is sUser a lookup?
 

Users who are viewing this thread

Back
Top Bottom