kikimayhay
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] & "")
Actually Chr(34) is a double quote character ... just for clarity ... Chr(39) is a single quote .
mx
mx
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
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.
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
^
mx
ASKER
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)
<<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.
This is treating it as if it was a numeric field. Is Account ID numeric or text?
JimD.
ASKER
it's a simple text box so - text
I meant Account, not Account ID
JimD
JimD
ASKER
sorry Account ID is an autonumber field
Account is a text field
Account is a text field
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
CurAcID = DLookup("[AccountID]", "[Accounts]", "[Account] =" & Chr(34) & Me.txtAccountLookUp & Chr(34) )
should work
mx
ASKER
That worked
CurAcID = DLookup("[AccountID]", "[Accounts]", "[Account] =" & chr$(34) & [Me.txtAccountLookUp] & chr$(34))
Chr$(34) is the quote character.
JimD.