DLookup in text box not working (1 Viewer)

xyba

Registered User.
Local time
Today, 18:51
Joined
Jan 28, 2016
Messages
189
In a form I want a dlookup to return the text value in UserAccess field in my table tblEmployees where the value in the table field strEmpName matches the value entered in text box txtUsername on the same form.

I've entered the below dlookup in the form textbox but it keeps returning a Name? error.

Also, Access keeps adding the square brackets around Me.txtUsername.

Code:
=DLookUp("UserAccess","tblEmployees","strEmpName = '" & Me.txtUsername & "'")

Code:
=DLookUp("UserAccess","tblEmployees","strEmpName = '" & [Me].[txtUsername] & "'")

Can anyone please shed any light on why I'm getting the error and why Access is placing the brackets around the control name?
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:51
Joined
Sep 21, 2011
Messages
14,046
I don't think entering that as source will work, as Access will not recognise the Me?

Try without.?

I know that syntax would work in an event like Form_Current as I do the same.

HTH

Edit:
Just tested and this works
Code:
=DLookUp("Amount","Transactions","ID=" & [ID])
 
Last edited:

xyba

Registered User.
Local time
Today, 18:51
Joined
Jan 28, 2016
Messages
189
I don't think entering that as source will work, as Access will not recognise the Me?

Try without.?

I know that syntax would work in an event like Form_Current as I do the same.

HTH

Edit:
Just tested and this works
Code:
=DLookUp("Amount","Transactions","ID=" & [ID])

Removing the Me does remove the Name? error but results in a blank field.
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:51
Joined
Sep 21, 2011
Messages
14,046
Does the dlookup actually return anything?
Try it in the immediate window on a breakpoint on the form.

I know that syntax worked as I tried it on a form of mine.
 

xyba

Registered User.
Local time
Today, 18:51
Joined
Jan 28, 2016
Messages
189
I've managed to get this to work using:

Code:
=DLookUp("[strEmpName]","[tblEmployees]","[1ngEmpID]=" & [TxtUsername])

As I looked deeper into the issue, it was because of referencing a select query and the wrong column of the query was being referenced.

Thanks for your help Gasman
 

Users who are viewing this thread

Top Bottom