DLookup Help (1 Viewer)

xyba

Registered User.
Local time
Today, 10:34
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] & "'")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:34
Joined
May 7, 2009
Messages
19,230
you don't add quote if the Box is numeric:

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

xyba

Registered User.
Local time
Today, 10:34
Joined
Jan 28, 2016
Messages
189
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?
 

Minty

AWF VIP
Local time
Today, 10:34
Joined
Jul 26, 2013
Messages
10,369
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.
 

xyba

Registered User.
Local time
Today, 10:34
Joined
Jan 28, 2016
Messages
189
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.
 

Minty

AWF VIP
Local time
Today, 10:34
Joined
Jul 26, 2013
Messages
10,369
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.
 

xyba

Registered User.
Local time
Today, 10:34
Joined
Jan 28, 2016
Messages
189
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

Top Bottom