0% found this document useful (0 votes)
15 views2 pages

New Text Document

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

New Text Document

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Dim db As DAO.

Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim lngUserID As Long
Dim strPassword As String
Dim strUserRole As String

' Check if a username is selected


If IsNull(Me.cboUsername) Or Me.cboUsername = "" Then
MsgBox "Please select a username.", vbExclamation, "Username Required"
Me.cboUsername.SetFocus
Exit Sub
End If

' Check if a password is entered


If IsNull(Me.txtpassword) Or Me.txtpassword = "" Then
MsgBox "Please enter a password.", vbExclamation, "Password Required"
Me.txtpassword.SetFocus
Exit Sub
End If

' Get user input


lngUserID = Me.cboUsername.Value
strPassword = Me.txtpassword.Value

' SQL query to join tblUsers and SecurityLevel


strSQL = "SELECT tblUsers.Username, SecurityLevel.UserRole " & _
"FROM tblUsers INNER JOIN SecurityLevel ON tblUsers.RoleID =
SecurityLevel.RoleID " & _
"WHERE tblUsers.UserID=" & lngUserID & " AND tblUsers.Password='" &
strPassword & "'"

' Open the database and the recordset


Set db = CurrentDb()
Set rst = db.OpenRecordset(strSQL)

' Check if the user exists and get the role


If Not rst.EOF Then
strUserRole = rst!UserRole

' Control user movement based on role


If strUserRole = "Admin" Then
MsgBox "Access Granted.... Welcome, " & rst!UserName & " You May
Proceed!", vbInformation, "Login Success"
DoCmd.OpenForm "frmAdmin" ' Replace with the actual form name for Admin
ElseIf strUserRole = "Secretary" Then
MsgBox "Access Granted.... Welcome, " & rst!UserName & " You May
Proceed!!", vbInformation, "Login Success"
DoCmd.OpenForm "frmMain" ' Replace with the actual form name for
Secretary
Else
MsgBox "Your role is not recognized.", vbExclamation, "Login Error"
' Handle other roles or provide a default form
End If

' Close the login form


DoCmd.Close acForm, "Login"

Else
' User not found, display error
MsgBox "Invalid Password.", vbCritical, "Login Failed"
Me.txtpassword = ""
Me.cboUsername = ""
End If

' Clean up
rst.Close
Set rst = Nothing
Set db = Nothing

You might also like