Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLookup using text criteria?

Status
Not open for further replies.

claytonjgordon

Technical User
Jul 21, 2004
37
US

Can you use two text fields in the criteria section of the Dlookup function?

I'm trying to create a feature where it takes the user's network ID using
Code:
Me.TempID = Environ("username")

and then compares it to a table where I have various users which I want to have exclusive access to a spesific feature. i.e., if me.tempID = one of the user names from the table, then it will allow the action. Otherwise, it will pop up a msgbox or something.

I can get DLookup to work when I'm using fields that are number based in the criteria, but I'm getting a "you canceled the previous operation' error when I use text fields.
Code:
VarID = DLookup("[FULLNAME]", "UserTbl", "[USERID] =" & Me!TempID)


Dominus Nihil
(Master of Nothing)
 
You can add extra field/value pairs as necessary.

[tt]
VarID = DLookup("[FULLNAME]", "UserTbl", "[USERID] =" & Me!TempID & "[another_field]=" & Me!myOtherField)
[/tt]
Of course, if your second field is a string, you'll need to enclose your string with quotes. Something like this:
[tt]
VarID = DLookup("[FULLNAME]", "UserTbl", "[USERID] =" & Me!TempID & "[another_field]='" & Me!myOtherField) & "'")
[/tt]
HTH,
Larry


 
Thank you so much. That was it, I was leaving out the signle quotes around the last part of the criteria:
Code:
"[USERID] = '" & Me!TempID & "'")

That was driving me crazy!!!

Thanks again!


Dominus Nihil
(Master of Nothing)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top