DLookup Error

G

Guest

I have a form that looks at the user logon name, then performs a DLookup in a
table to retrieve permission levels.

CODE:
varUserName = DLookup("[FullName]", "tblUsers", "[UserID] = '" & varUserID &
"'")

I receive an error if the user is not listed in the table.

I would like to assign a 'guest' permission level if the user is not listed.

How do I trap this?
 
A

Allen Browne

What error do you get? How is varUseName declared?

DLookup() returns Null if no match is found.
If you declared:
Dim varUserName As Variant
it should be able the Null. However, if you declared it as a string, you
will not be able to assign a Null to the string variable.
 
G

Guest

Try using the Nz function to replace the Null (that return if no record is
found) with guest

varUserName = Nz(DLookup("[FullName]", "tblUsers", "[UserID] = '" &
varUserID &
"'"),"Guest")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DLookup Problem 1
Using DLOOKUP in code entries 7
Dlookup on form - help please 2
#error using dlookup 3
DLookup 2
String and Dlookup 3
DLookup Syntex error it is killing me 7
dlookup 2

Top