Can anyone help with this dlookup issue? (1 Viewer)

gojets1721

Registered User.
Local time
Today, 07:53
Joined
Jun 11, 2019
Messages
430
In the control source of a field, I am hoping to look up a field in a separate table. Essentially, it's a manager field. I have a table full of manager names and their locations. If the location on the report matches the location in the table, I want that managers name to show up on the report. Here's my code. Access is asking me to input 'me' when i use this code so clearly something is wrong

Code:
=Nz(DLookUp("ManagerName","tblManagers","Location='" & [Me.][Location] & "'"),"")
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:53
Joined
Oct 29, 2018
Messages
21,485
Yeah, just take out the [Me.] part.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:53
Joined
Feb 19, 2002
Messages
43,330
"Me." is a reference to the current form from WITHIN that form's class module. It cannot be used outside of the form's Class module.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:53
Joined
Feb 28, 2001
Messages
27,210
The syntax you presented is what is getting you. [Me.] doesn't refer to anything because the closing ] "cuts off" the syntax prematurely. Since there is no space character in the name, Me.Location should work just fine - as long as field Location actually appears by that name in the report. When there are no embedded spaces or special characters in a name, you USUALLY don't need enclosing brackets. (There are rare exceptions to that rule.) And Me. as a prefix (without the brackets) works in a report because that IS a case where a class module is likely to be present.
 

Users who are viewing this thread

Top Bottom