Link to home
Start Free TrialLog in
Avatar of kikimayhay
kikimayhayFlag for United States of America

asked on

Dlookup returns error 2465 can't find the field | referred to your in expression

We created a dlookup  as shown below which works fine in most cases but if the me.txtAccountLookup contains a hyphen we get the error 2465 cannot find the field '|' referred to in your expression. I cannot see why this expression does not work. Please offer guidance to resolve this issue.
CurAcID = DLookup("[AccountID]", "[Accounts]", "[Account] =" & [Me.txtAccountLookUp] & "")

Open in new window

Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

You got an extra quote on the end.  Format it like this for text:
CurAcID = DLookup("[AccountID]", "[Accounts]", "[Account] =" & chr$(34) &  [Me.txtAccountLookUp]  & chr$(34))  
Chr$(34) is the quote character.
JimD.
Actually Chr(34) is a double quote character ... just for clarity ...  Chr(39) is a single quote .

mx
Avatar of kikimayhay

ASKER

I applied the code you provided however I receive the same results
try this - no brackets

CurAcID = DLookup("[AccountID]", "[Accounts]", "[Account] =" & Chr(34) & Me.txtAccountLookUp & Chr(34) )

mx
try it this way without the square brackets:
CurAcID = DLookup("[AccountID]", "[Accounts]", "[Account] =" & chr$(34) &  Me.txtAccountLookUp  & chr$(34))  
 and if that still fails, but a break point on the line and execute the code.  When it stops, go to the debug window and type:
 Debug.? Me.txtAccountLookup
 and you'll probably figure out what's wrong.  I'm assuming this is executing in a form and the account lookup is based on a text field and not a numeric.
JimD.
also ... maybe "[Account] =" should be "[Accounts] ="
                                                                               ^

mx
                                                                       
using your code produced ole errors my original dllookup will work as long as the textbox does not have any alpha chacters in it, and just found out it drops leading zeros.
 

CurAcID = DLookup("[AccountID]", "Accounts", "[Account] =" & Me.txtAccountLookUp.Text)

Open in new window

<<CurAcID = DLookup("[AccountID]", "Accounts", "[Account] =" & Me.txtAccountLookUp.Text) >>
This is treating it as if it was a numeric field. Is Account ID numeric or text?
JimD.
it's a simple text box so - text
I meant Account, not Account ID
JimD
sorry Account ID is an autonumber field
Account is a text field
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If it's Text ... and [Account]  - the field in the table has a Data Type of Text ...   then what we both posted

CurAcID = DLookup("[AccountID]", "[Accounts]", "[Account] =" & Chr(34) & Me.txtAccountLookUp & Chr(34) )

should work

mx
That worked