Hi , Please follow ,
1) Create a Modules named "GVar" and copy this code paste inside.
Option Compare Database
Global strUser As String
Global strRole As String
2)Create 2 text box , User and Password .
-set the User's Text box name to cboUser
-set the Password's Text box name to txtPassword
3)Creat a Login button , set an event in "On Click.
-set the Login button's name to cmdLogin ,
-copy this into the event procedure
Private Sub cmdLogin_Click()
Call Login
End Sub
Public Sub Login()
On Error GoTo ErrorHandler:
If IsNull([cboUser]) = True Then 'Check UserName
MsgBox "Username is required"
ElseIf IsNull([txtPassword]) = True Then 'Check Password
MsgBox "Password is required"
Else
'Compare value of txtPassword with the saved Password in YOUR USER TABLE
If Me.txtPassword.Value = DLookup("Password", "YOUR USER TABLE", "[UserName]='" & Me.cboUser.Value & "'") Then
DoCmd.Close acForm, "frmLogin", acSaveNo
MsgBox "Welcome, " & strUser, vbOKOnly, "Welcome"
DoCmd.OpenForm "WHAT FORM YOU WANT TO OPEN", acNormal, "", "", , acNormal
Else
MsgBox "Invalid Password. Please try again.", vbOKOnly, "Invalid Password"
intLogAttempt = intLogAttempt + 1
txtPassword.SetFocus
End If
End If
'Check if the user has 3 wrong log-in attempts and close the application
If intLogAttempt = 3 Then
MsgBox "You do not have access to this database.Please contact Super Administrator. Ext : 314 " & vbCrLf & vbCrLf & _
"Application will exit.", vbCritical, "Restricted Access!"
Application.Quit
End If
ErrorHandler:
End Sub