poohbear2012
Registered User.
- Local time
- Today, 20:29
- Joined
- Jan 8, 2012
- Messages
- 30
I have designed a user login form in Access 2010 which enables users to enter a password to login into the database. I wish the form to close and go to the default Home page form.
I have written the following VBA code under the button to undertake the "OnClick" function of the Login button task but it still is not working. The Home page loads but the login form does not close. Am not sure what is wrong as have used the DoCmd.Close and open function.
Private Sub cmdLogin_Click()
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
If IsNull(Me.Password) Or Me.Password = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.Password.SetFocus
Exit Sub
End If
If Me.Password.Value = DLookup("Password", "Employees", _
"[ID]=" & Me.cboEmployee.Value) Then
ID = Me.cboEmployee.Value
DoCmd.Close acForm, "Logon Dialog", acSaveNo
DoCmd.OpenForm "Home", acNormal
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.Password.SetFocus
End If
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
I have written the following VBA code under the button to undertake the "OnClick" function of the Login button task but it still is not working. The Home page loads but the login form does not close. Am not sure what is wrong as have used the DoCmd.Close and open function.
Private Sub cmdLogin_Click()
If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
Me.cboEmployee.SetFocus
Exit Sub
End If
If IsNull(Me.Password) Or Me.Password = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.Password.SetFocus
Exit Sub
End If
If Me.Password.Value = DLookup("Password", "Employees", _
"[ID]=" & Me.cboEmployee.Value) Then
ID = Me.cboEmployee.Value
DoCmd.Close acForm, "Logon Dialog", acSaveNo
DoCmd.OpenForm "Home", acNormal
Else
MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
"Invalid Entry!"
Me.Password.SetFocus
End If
intLogonAttempts = intLogonAttempts + 1
If intLogonAttempts > 3 Then
MsgBox "You do not have access to this database.Please contact admin.", _
vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub