I have a table with usernames, passwords and security levels in form of number 1,2,3...
What I want is when you open a database using a login form where you enter you username and password,and you login that based on your security level you are allowed, when clicking on certain buttons to open forms, or if you dont have big enough security level to not be able to open them.
I am using a VBA code for a login screen from a video on youtube (https://youtu.be/356ylQn6kkA) where he uses recordsets to find users (VBA code for it below).
So where I need help is with connecting the security level with the buttons so if they dont open if security level is less then 2 for example.
Is there anything I should add to the login code, and how can I code buttons to check for the security level. My problem is that I dont know how to get to the security level number of the person that is login so that it would check it.
Code for login screen button
What I want is when you open a database using a login form where you enter you username and password,and you login that based on your security level you are allowed, when clicking on certain buttons to open forms, or if you dont have big enough security level to not be able to open them.
I am using a VBA code for a login screen from a video on youtube (https://youtu.be/356ylQn6kkA) where he uses recordsets to find users (VBA code for it below).
So where I need help is with connecting the security level with the buttons so if they dont open if security level is less then 2 for example.
Is there anything I should add to the login code, and how can I code buttons to check for the security level. My problem is that I dont know how to get to the security level number of the person that is login so that it would check it.
Code for login screen button
Code:
Private Sub btnLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tbl1Employees", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.txtUserName & "'"
If rs.NoMatch Then
Me.lblWrongUser.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.lblWrongUser.Visible = False
If rs!Password <> Nz(Me.txtPassword, "") Then
Me.lblWrongPass.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
Me.lblWrongPass.Visible = False
DoCmd.OpenForm "frmMain"
DoCmd.Close acForm, Me.Name
End Sub