DLookup Error

P

Posse John

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.
 
O

Ofer Cohen

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


Top