First of all, let me congratulate you for the excellent work you have been doing through this forum and apologize if my question may sound trivial to some, or has been answered before. What I am trying to do is to assign roles to the users of my db and programmatically allow them (according to their assigned role) to have access to some of the db’s functionalities.
So, I have a table (=LoginTable) with four fields: userID (autonumber), username (text), password (text) and Role (text):
|userID|username|password|Role|
A basic login form (=LoginForm) has been created with two unbound fields namely: usernamecombo (having as a source the username field of the LoginTable) and of course password (=passwordtxt). A button is also added to enter the db’s switchboard. The code I’ve written for the “Enter db” button works fine so once this is pressed the user sees the switchboard, but I am stuck with writing the correct code about the user’s role once a button on the switchboard is pressed. For example, if the user’s role is “user” then a message box will notify him/her that access is not granted etc. I thought of writing a code once the button is pressed similar to:
Dim userRole as string
userRole = dlookup(“[Role]”,”LoginTable”,…..(criteria))
if userRole = “user” then msgbox ....
Else
Docmd.OpenForm "MAIN"
End if
Probably I am doing something wrong with the criteria in the dlookup line, because no matter what I have tried, I always get an error message. Do I have to declare the role variable as a public variable in order to use it while I am in a form other than the LoginForm?
Any suggestions are more than welcome.
Thank you in advance for your assistance.
So, I have a table (=LoginTable) with four fields: userID (autonumber), username (text), password (text) and Role (text):
|userID|username|password|Role|
A basic login form (=LoginForm) has been created with two unbound fields namely: usernamecombo (having as a source the username field of the LoginTable) and of course password (=passwordtxt). A button is also added to enter the db’s switchboard. The code I’ve written for the “Enter db” button works fine so once this is pressed the user sees the switchboard, but I am stuck with writing the correct code about the user’s role once a button on the switchboard is pressed. For example, if the user’s role is “user” then a message box will notify him/her that access is not granted etc. I thought of writing a code once the button is pressed similar to:
Dim userRole as string
userRole = dlookup(“[Role]”,”LoginTable”,…..(criteria))
if userRole = “user” then msgbox ....
Else
Docmd.OpenForm "MAIN"
End if
Probably I am doing something wrong with the criteria in the dlookup line, because no matter what I have tried, I always get an error message. Do I have to declare the role variable as a public variable in order to use it while I am in a form other than the LoginForm?
Any suggestions are more than welcome.
Thank you in advance for your assistance.