Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
After designing the Ultimate Login Form, you need to create a user table for setting up user authentication to function. To get the functionality of the login form, you have to create a second form like the main dashboard which contains a logout functionality so the user can redirect to the login form after logging off.
Create a User table with these fields:
Field Name | Data Type | Description |
---|---|---|
uid | AutoNumber | User ID |
uname | Short Text | Name |
udate | Date/Time | User Date |
ugender | Short Text | User Gender |
uage | Number | User Age |
uusername | Short Text | User Name |
upassword | Short Text | Password |
ustatus | Short Text | User Status |
Fill data with some demo records.
Create a Main Dashboard demo form with a Logout button. The user will be redirected to the Login Form after successful logoff.
Hence, the Main Dashboard form will be the first appearance for the user after login, you can create a Multi-User with separate dashboard forms. For example, the Admin Dashboard will be open for Admin accounts and the User Dashboard will be open for Users. Later on, you can create User-level authentications as well. Refer to the Expense Management Project to assign a Multi-User System.
Before Login Button On click event code, you need to make a label for “Incorrect Username or Password” and hide it from the Format properties.
Login Button On Click event Code
Private Sub btn_login_Click()
If DCount("uusername", "usertable", "uusername = '" & txt_username & "' and upassword = '" & txt_password & "'") = 0 Then
Me.Lbl_incorrect.Visible = True
Else
DoCmd.Close acForm, "LoginForm"
DoCmd.OpenForm "MainForm"
End If
End Sub
The login button must be working fine to open the Dashboard Form if the Username and Password are correct. Please make sure that the name of the form is “MainForm”.
Logout Button Code to close the Main Form and open the Login Form:
Private Sub btn_logout_Click()
responce = MsgBox("Do you really want to logout?", vbYesNo + vbQuestion, "| Logout Confirmation |")
If response = vbYes Then
DoCmd.Close acForm, "MainForm", acSaveNo
DoCmd.OpenForm "LoginForm"
Else
Cancel = True
End If
End Sub