I have a table with name tbl_login with fields:
UserID
FirstName
LastName
UserName
Password
I also have a form with name frm_login with textboxes:
One for Username with textbox name : txt_username
the other for passowrd with textbox name : txt_password
i have a command button with name cmd_login with the following codes behind it.
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
If Trim(Me.txt_username.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Username should not be left blank.", buttons:=vbInformation, title:="Username Required"
Me.txt_username.SetFocus
Exit Sub
End If
If Trim(Me.txt_password.Value & vbNullString) = vbNullString Then
MsgBox prompt:="Password should not be left blank.", buttons:=vbInformation, title:="Password Required"
Me.txt_password.SetFocus
Exit Sub
End If
'query to check if login details are correct'
strSQL = "SELECT FirstName FROM tbl_login WHERE Username = """ & Me.txt_username.Value & """ AND Password = """ & Me.txt_password.Value & """"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL)
If rst.EOF Then
MsgBox prompt:="Incorrect username/password. Try again.", buttons:=vbCritical, title:="Login Error"
Me.txt_username.SetFocus
Else
MsgBox prompt:="Hello, " & rst.Fields(0).Value & ".", buttons:=vbOKOnly, title:="SOFTWARE"
DoCmd.OpenForm "A"
I will like to create a new field in tbl_login with the name Access_level which will contain the following user access permissions;
Administrator
Accounts
Secretary
I will like my code to be re modified such that:
when login with access_level administrator, it should open form A
when login with access_level Accounts, it should open form B
when login with access_level Secretary, it should open form C
Any help with this will be greatly appreciated