Saturday, December 4, 2010

Creating a User Log in Form Microsoft Access 2003!


This User Log in Form Sample is desinged in Microsoft Access 2003, including VBA programming, which can interactively allow users to log in to the next form or to the main form with a Valid User Name and Password.

Figure 1
The Combo Box in the form will help users to collect username from the Table (in this Project as tblUserAccount) with is connected with DLookup function in VBA programming.
Figure 2
Coming to the Project, at first create a table with a detailed fields as above figure mo 2, and keep some neccessary record for your further use.
Then create a Form having following properties,
On the Log in button write the following VBA code.

Private Sub cmdLogin_Click()
'To ignore null values
If IsNull(Me.cboUserName) Or Me.cboUserName.Value = "" Then
MsgBox "Please enter a valid User Name or contact to your Administrator!", vbInformation, "User Name required!"
Me.cboUserName.SetFocus
Exit Sub
End If
If IsNull(Me.txtPassword) Or Me.txtPassword.Value = "" Then
MsgBox "Please enter a valid Password!", vbInformation, "Password required!"
Me.txtPassword.SetFocus
Exit Sub
End If
'To check avaibility of User Account and return the value
If Me.txtPassword.Value = DLookup("Password", "tblUserAccount", "[UserID]=" & Me.cboUserName.Value) Then
UserID = Me.cboUserName.Value
a = UserName
DoCmd.Close acForm, "frmLogin", acSaveNo
MsgBox "Welcome '" & UserID & "' to My World!", vbInformation, "Congratulations!"
DoCmd.OpenForm "frmWelcome"
Else
MsgBox "User Name or Password, you typed do not MATCHE!", vbExclamation, "Incorrect Password!"
cboUserName.Value = ""
txtPassword.Value = ""
Me.cboUserName.SetFocus
End If
' If log in attempt is wrong for more than three times than close the application
intLogOnAttempts = intLogOnAttempts + 1
If intLogOnAttempts > 3 Then
MsgBox "Sorry! You have applied Invalid Password. You do not have access to the database, please consider with your Administrator.", vbCritical, "Restricted User!"
Application.Quit
End If
End Sub

If your User Name and password is correct than a form as below will appears..

Now run you User Log in Form.
Thank you,

No comments:

Post a Comment