Can't get login dialog box to close

ronniek68

New member
Local time
Today, 18:25
Joined
Nov 13, 2012
Messages
1
I have a database with login dialog box, everything works fine, but when I enter password and click button, the dialog box does not close. Please help. Below is my code.


Option Compare Database

Private Sub CmndExit_Click()

DoCmd.Quit


End Sub


Private Sub CmndLogin_Click()


'Check to see if data is entered into the UserName combo box
If IsNull(Me.cboemployee) Or Me.cboemployee = "" Then
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
'Me.cboemployee.SetFocus
Me.CmndLogin.SetFocus
Exit Sub
End If


'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If


'Check value of password in tblEmployees to see if this matches value chosen in combo box
If Me.txtPassword.Value = DLookup("Password", "tbl login", "[Employee name]=" & Me.cboemployee.Value) Then
MyEmpID = Me.cboemployee.Value

'Close logon form and open splash screen
DoCmd.Close acForm, "frmlogin"
DoCmd.OpenForm "switchboard"
Else
MsgBox "Password Invalid. Please Try Again", vbCritical + vbOKOnly, "Invalid Entry!"
Me.txtPassword.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
 
I have a feeling that the problem may be in your DLookup:

Code:
If Me.txtPassword.Value = DLookup("Password", "tbl login", "[Employee name]=" & Me.cboemployee.Value)

You are asking Access to compare a string , from the [Employee name] field, with a number , " & Me.cboemployee.Value.

I think it should be '" & Me.cboemployee.Value & "'" to return a string from the combo box, otherwise I believe it returns a number.

You should use Option Explicit just under your Option Compare Database so that Access will alert you to any undeclared variables and datatype mismatches.
 

Users who are viewing this thread

Back
Top Bottom