How to reference value of string variable in If statement

CodeCurious

New member
Local time
Yesterday, 19:16
Joined
Oct 26, 2012
Messages
7
I'm writing a function that mimics login behavior for an Access database. Here's an overview:
- User enters a login ID in a textbox (txtLogin) in a form
- VBA Public Function uses DLookup to lookup the user's role in a table in the database, based on the value in txtLogin, and stores it in a string variable (sRole).

So far so good. The function is properly retrieving the user's role based on their login ID. But then I'd like to make some decisions based on the value of sRole. For example, if the user role is "NotAdmin", I'd like to hide a tab control that lists admin functions. When I use the code below, the compiler seems to think that "NotAdmin" is an undefined variable rather than the value of a declared string variable (sRole):

If sRole = NotAdmin Then
do something to make admin tab invisible
End If

This is the error message I get: "Compile error: Variable not defined" and the compiler seems to have choked on NotAdmin.

I'm new to VBA, so greatly appreciate any help you can provide.
 
If a sRole = "NotAdmin"

With the quotes. That is for strings.
 
Thanks very much. I thought I had tried that at one point and was still getting the error. But when I try it now, works fine.
 

Users who are viewing this thread

Back
Top Bottom