Dlookup syntax

Can someone tell me what is wrong with this onprint event code?

Me.txtCustName = DLookup("[CompanyName]", "tblCustomers", "[CustNum] = Me.txtCustNum)
SteveL13Asked:
Who is Participating?
 
mbizupCommented:
Change the criteria to

"Custnum =" & me.custnum
0
 
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
If CustNum is a text field, your going to need:

 "Custnum = " & chr$(34) & me.custnum & chr$(34)

 The Chr$(34) gives you the quote character, so you end up with:

 Custnumb = "<some value>"

 Would be worth it to read:

http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_12-Dlookup-and-the-Domain-Functions.html

 which discusses passing strings within a string.

HTH
Jim.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.