DLookup Not Working

L

Lisa

I have a form i want to create a DLookup where I get the Last_Name on the
tblUserNameTest when the field txtUser on the active form equals the
User_IDon the tblUserNameTest table.

I have this and it is not working what am I doing wrong?

=DLookUp("[Last_Name]","tblUserNameTest","User_ID = " & [txtUser])

Whatever you can do to help would be greatly appreciated.

Thanks.

lisa
 
K

Klatuu

What data type is the field User_ID?
Your code indicates it is a numeric data type.
If txtUser is a form control on the current form, you should be qualifying
it with either Me. or Me!
 
D

Dirk Goldgar

Lisa said:
I have a form i want to create a DLookup where I get the Last_Name on the
tblUserNameTest when the field txtUser on the active form equals the
User_IDon the tblUserNameTest table.

I have this and it is not working what am I doing wrong?

=DLookUp("[Last_Name]","tblUserNameTest","User_ID = " & [txtUser])

Whatever you can do to help would be greatly appreciated.


Looks okay, if User_ID is a numeric field. If User_ID is a text field then
use:

(if User_ID won't contain an apostrophe):

=DLookUp("[Last_Name]","tblUserNameTest",
"User_ID = '" & [txtUser] & "'")

(if User_ID may contain an apostrophe, but not a double-quote (") ):



=DLookUp("[Last_Name]","tblUserNameTest",
"User_ID = """ & [txtUser] & """")

If the User_ID may contain both apostrophes and double-quotes, it's more
complicated. Let me know if you need that.

And, of course, if User_ID is a number field, the above suggestions don't
apply and something else is wrong.
 
D

Dirk Goldgar

Klatuu said:
If txtUser is a form control on the current form, you should be qualifying
it with either Me. or Me!


Except that I take this to be a controlsource expression, in which case the
Me keyword would not be appropriate. If this is an expression used in VBA
code, then I would agree.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

#error using dlookup 3
Trying to use DLookup 3
Dlookup Question 5
DLookup Alternative 11
Yet another DLookup problem! 5
dlookup right from Help not working 2
Hide Form Controls based on User 5
dlookup problem 3

Top