DLookup Help

xyba

Registered User.
Local time
Today, 21:46
Joined
Jan 28, 2016
Messages
189
Hi, I need some help with a DLookup expression in the AfterUpdate event of a form text box, please.

I have a query (qryLocate with two fields, Box and Row

I want to look up the value of text box txtBoxID in the field Box in qryLocate and return the value in Row.

I tried the below but it didn't work, probably because I've not used Dlookup much in Access.

Code:
=DLookUp("[Row]","[qryLocate]","[qryLocate]![Box] = '" & [Me].[txtBoxID] & "'")
 
you don't add quote if the Box is numeric:

=DLookUp("[Row]","[qryLocate]","[Box] = " & [Me].[txtBoxID] )
 
you don't add quote if the Box is numeric:

=DLookUp("[Row]","[qryLocate]","[Box] = " & [Me].[txtBoxID] )

Thanks arnel, though that throws up a #Name? error. I've checked the form and there are no controls named Row or Box and there is definitely one called txtBoxID. Could there be another reason for this error?
 
The Me syntax isn't correct
Code:
=DLookUp("Row","qryLocate","Box = " & Me.txtBoxID )

You only need the square brackets for field names with spaces or that are reserved words.
 
The Me syntax isn't correct
Code:
=DLookUp("Row","qryLocate","Box = " & Me.txtBoxID )

You only need the square brackets for field names with spaces or that are reserved words.

Thanks Minty. However, Access didn't seem to like that idea as it kept adding the square brackets each time I completed the expression.

It got me to thinking, though, and I solved it by removing the [Me].

Thanks.
 
Is this on a form? In that case it's correct, I thought this was in a VBA module where the Me. prefix refers to the current form object.
 
Is this on a form? In that case it's correct, I thought this was in a VBA module where the Me. prefix refers to the current form object.

Yes, in a form. Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom