I use the following code to manage user logon success:
On the same form where that code resides there is a cancel button with the following code:
The behaviour that is strange is that if no user information is present and I click cancel, the database closes as it should.
However, If I enter valid user information within the username/password text boxes and click cancel... I get logged in.
Can anyone explain why this is happening? I cant for the life of me see how the Login and Cancel button can be linked here =|
Regards,
Chris
Code:
Private Sub cmdOk_Click()
On Error GoTo Err_cmdOk_Click
'-----------------------------------------------------------------------------------------------------------------------------
' This code is used to validate users found in the tblSecurity table. If the wrong user name or password is
' provided access is denied.
'-----------------------------------------------------------------------------------------------------------------------------
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim rstV As Recordset
Dim stDocName As String
Dim stLinkCriteria As String
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblSecurity", dbOpenDynaset)
If Not IsNull(Me.txtUser) And Not IsNull(Me.txtPassword) Then
rst.FindFirst "Password = '" & Me.txtPassword & "'" & " And UserID = '" & Me.txtUser & "'"
If rst.NoMatch Then
MsgBox "You entered the wrong User Name or Password." & Chr(13) & _
"Please enter the correct User Name and Password or " & Chr(13) & _
"contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
ElseIf Me.txtPassword = "password" Then
MsgBox "This is the first time using the database or your passowrd has been reset." & Chr(13) & _
"You must change your password before you can enter the database.", _
vbOKOnly + vbExclamation, "Change Password"
stDocName = "frmUserLogonNew"
stLinkCriteria = "[UserID]=" & "'" & Me![txtUser] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Else
stDocName = "frmSplashScreen"
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
Else
MsgBox "You left the User Name and/or Password blank." & Chr(13) & _
"Please enter the correct User Name and Password or " & Chr(13) & _
"contact the Database Adminstrator for assistance.", vbOKOnly + vbCritical, "Logon Denied"
End If
With Forms!frmhidden
.txtViewID = rst.Fields("ViewID")
.txtAccessID = rst.Fields("AccessID")
.txtActive = rst.Fields("Active")
.txtPassword = rst.Fields("Password")
.txtUserID = rst.Fields("UserID")
.txtSecurityID = rst.Fields("SecurityID")
.txtFName = rst.Fields("FName")
.txtSName = rst.Fields("SName")
.txtEMailAd = rst.Fields("EmailAd")
.txtUdept = rst.Fields("UDept")
End With
rst.Close
Exit_cmdOk_Click:
Exit Sub
Err_cmdOk_Click:
MsgBox err.Description
Resume Exit_cmdOk_Click
End Sub
Code:
Private Sub cmdCancel_Click()
On Error GoTo Err_cmdCancel_Click
Dim intResponse As Integer
Forms!frmUserLogon.Visible = False
intResponse = MsgBox("Warning: By canceling, you are about to completely exit the database." & Chr(13) & _
"Are you sure you want to do this?", vbYesNo + vbExclamation, "Exiting Database")
Select Case intResponse
Case vbYes
DoCmd.Quit
Case Else
Forms!frmUserLogon.Visible = True
End Select
Exit_cmdCancel_Click:
Exit Sub
Err_cmdCancel_Click:
MsgBox err.Description
Resume Exit_cmdCancel_Click
End Sub
However, If I enter valid user information within the username/password text boxes and click cancel... I get logged in.
Can anyone explain why this is happening? I cant for the life of me see how the Login and Cancel button can be linked here =|
Regards,
Chris