Microsoft Access Sign-In Form is one of the most needed by MS access programmers. Using sign in form will definitely secure your database. However, before creating a log-in form, you have to create a user table with identified user ID and username. The steps to create the login form are:
- Create a table and give it a name.
- Add three fields: User ID, Username, and Password. The username has to be unique.
- Set the input mask of the User Password to “Password”.
- Create a Modal Dialog and then insert two unbounded fields. One for the username and the other for the password.
- Insert two commands: OK and Exit buttons.
- Right click on each button and paste the below VBA Codes to each one based on their event procedures.
MS Access login form with password download
Exit Button VBA Code:
If MsgBox("Quit Program?", vbYesNo, "Quit") = vbYes Then DoCmd.Quit
OK Button VBA Code For Microsoft Access Sign in Form:
Dim rs As Recordset
Dim Security, User As String
On Error GoTo Err:
Set rs = CurrentDb.OpenRecordset("tblUser", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.User & "'"
' Check Username & Password
If rs.NoMatch = True Then
Me.User.SetFocus
MsgBox "Wrong User Name", vbCritical, "Login"
Exit Sub
End If
If IsNull(Me.txtPassword) Then
Me.txtPassword.SetFocus
MsgBox "Insert Password.", vbCritical, "Login"
Exit Sub
End If
If rs!UserSecurity <> Me.txtPassword Then
MsgBox "Wrong Password, Please try again.", vbCritical, "Login"
Else
DoCmd.OpenForm "frmMain", acNormal, , "UserName='" & Me.User & "'"
DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.Close acForm, "frmBackGround", acSaveNo
End If
Exit Sub
Err:
MsgBox Err.Description, vbCritical
The downloadable file will provide you with all the VBA codes for Microsoft Access Sign-In Form:
- Create Microsoft Access Login Form.
- Add, Remove, Edit users.
- Control Amin and users passwords.
- Authority to grant access command buttons.
- Auto Log out when idle for a specific time.
In addition to Microsoft Access Login Form, the downloadable file will also include the Idle timeout feature. You can refer to our post for MS Access Idle Timeout here.
* Login password: 123
To use Microsoft Access Programs,
you’ll need to have Microsoft Office installed including the bundle of MS Access or to download the free Microsoft Access 2016 run-time.
Please check our Pro Microsoft Access Programs here.