Login Form And User Level (1 Viewer)

ILA

New member
Local time
Today, 02:42
Joined
Jan 9, 2003
Messages
6
I have a table with the following

User Table

User ID, User Name, Pass, Level


I have a form with a combo-box from which they select there username, after they enter in the pass...

When a user selects its user name and enters his/her pass, I want them to go to different forms depending on the user level?

how can I do this, and also if possible is there a way to display the user name, on the form which will open., so letting the user know that he is logged in as...

what code can I use? or should I change this? btw: I cant use the inbuilt security features, its one of my project limits!!! thanks
 

Robert Dunstan

Mr Data
Local time
Today, 02:42
Joined
Jun 22, 2000
Messages
291
Hit there,

Below are some of the code that I use to test permission rights. Basically what I've done is declared public variables in a module and in they contain the login details.

Private Sub cmdOK_Click()

' Check to see if password is entered

If IsNull(txtPassword) = True Then
strMessage = "Please enter your password"
style = vbCritical
strTitle = "No Password Entered"

MsgBox strMessage, style, strTitle
txtPassword.SetFocus
Exit Sub
Else

'Gets the password stored in tblEmployees
strPassword = DLookup("[Password]", "tblEmployees", "[EmployeeID] = Forms!frmLogin!cboUserName")
'Gets the permission level stored in tblEmployees
Permission = DLookup("[Level]", "tblEmployees", "[EmployeeID] = Forms!frmLogin!cboUserName")
' Calls the userRights public function and assigns the value of the Permission variable
userRights (Permission)
'Gets the login name and stores it in the LoggedInAs public variable
LoggedInAs = DLookup("[EmployeeName]", "tblEmployees", "[EmployeeID] = Forms!frmLogin!cboUserName")

End If

If txtPassword <> strPassword Then
strMessage = "The Password you have entered is incorrect."
strMessage = strMessage & vbCr & vbCr
strMessage = strMessage & "Please enter it again."
style = vbCritical
strTitle = "Incorrect Password"

MsgBox strMessage, style, strTitle
Tries = Tries + 1
txtPassword.SetFocus

If Tries > 3 Then
DoCmd.Quit
End If
End Sub

The above code is in the On_Click event of cmdOk in my login form.

Now what I do in each of my forms, in the general declarations I declare a constant variable and assign a value to it e.g

Const userLevel = 2

Then in the forms On_Open event I compare the Permission variable with userLevel and if the Permission is >= userLevel then I allow the user access to the form.

Hopefully this helps you out

Good luck
Rob
 

Users who are viewing this thread

Top Bottom