Create Login Form Access
👉 Check out my grocery database, https://grocerydynamite.com/
We need a table that relates users to the level of access they have in the database. The 3 columns needed are Username, Password, and Security Level.
We need a form that lets us enter our password and check the database for validity and deny entry to invalid credentials. A VBA Macro is also needed to make this work.
The forms we need are
Admin
Login
Welcome
-Code-
Dim Userlevel As Integer
If IsNull(Me.username) Then
MsgBox “Please enter the correct username.”, vbInformation, “Username required”
Me.username.SetFocus
ElseIf IsNull(Me.password) Then
MsgBox “Please enter the correct Password.”, vbInformation, “Password required”
Me.password.SetFocus
Else
If (IsNull(DLookup("username", "UserAccount", "Username='" & Me.username.Value & "'"))) Or _
IsNull(DLookup("Password", "UserAccount", "Password='" & Me.password.Value & "'")) Then
MsgBox "Username or Password is Incorrect!", vbCritical, "Login Denied"
Me.username = ""
Me.password = ""
Me.username.SetFocus
Else
Userlevel = DLookup("[Security Level]", "UserAccount", "Username='" & Me.username.Value & "'")
If Userlevel = 1 Then
MsgBox "Access Granted... you may proceed!", vbInformation, "Authentication Succeeded"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
DoCmd.OpenForm "Welcome"
End If
If Userlevel = 2 Then
MsgBox "Access Granted... you may proceed!", vbInformation, "Authentication Succeeded"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
DoCmd.OpenForm "Admin"
End If
End If
End If
End Sub