DLookup Error

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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.
 
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")
 
Back
Top