This is what I have. I remember finding this code on some website. I slightly modified to meet my needs.
You will need a table with username and password stored and a form with username and paswword textboxes plus a command button.
I placed this code on the click event of the command button.
Option Compare Database
Private intLogonAttempts As Integer
Private Sub cmd_Login_Click()
'Check to see if data is entered into the UserName combo box
If IsNull(Me.txt_UserName) Or Me.txt_UserName = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.txt_UserName.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txt_Password) Or Me.txt_Password = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txt_Password.SetFocus
Exit Sub
End If
'Check value of password in tblEmployees to see if this matches value chosen in combo box
If Me.txt_Password.Value = DLookup("PASSWORD", "tbl_Employees", "[USERNAME]='" & Me.txt_UserName.Value & "'") Then
PubUserName = Me.txt_UserName
lngMyEmpID = Me.txt_UserName.Value
'Close logon form and open splash screen
DoCmd.close acForm, "frm_Login", acSaveNo
DoCmd.OpenForm "Switchboard"
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
Me.txt_Password.SetFocus
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub