Login Form Not Working as Expected - Please Help!

BlueStarBrite

Registered User.
Local time
Today, 15:49
Joined
Jan 15, 2009
Messages
23
Ok, so I have a login form in which has username and password fields. I am wanting to collect the logintime and the logout time for each user. Initially before I added the password code field, it was tracking the login/logout just fine. However, now its not. I am not sure where I went wrong and am starting to spin my wheels. :confused: Please help! Thanks in advance.

Here is my code for my LogIn Button:
Code:
Private Sub cmdLogIn_Click()
On Error GoTo Err_cmdLogIn_Click
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblLogTimes", dbOpenDynaset)
 
If IsNull(Me.Combo0) Then
    MsgBox "You must select a username!", vbInformation, "Required Data"
    Me.Combo0.SetFocus
    Exit Sub
'Else
End If
'Check to seeif data is entered into the passwordbox
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
    MsgBox "You must enter a Password!", vbInformation, "Required Data"
    Me.txtPassword.SetFocus
    Exit Sub
End If
'Check value of password in tblNames to see if this matches necessary value chosen in combobox
If Me.txtPassword.Value = DLookup("Password", "tblNames", "[ClientId]=" & Me.Combo0.Value) Then
lngMyEmpId = Me.Combo0.Value
'Open switchboard main menu
DoCmd.OpenForm "Switchboard"
Else
MsgBox "Password Invalid. Please Try Again!", vbInformation, "Invalid Entry"
    With rst
        .AddNew
        ![ClientID] = Me.Combo0
        .Update
        .Close
    End With
    MsgBox "Log In Successful"
End If
'If User Enters incorrect password 3 times, database will shut down
    intLogonAttempts = intLogonAttempts + 1
 
    If intLogonAttempts > 3 Then
        MsgBox "You do not have proper access to this database. Please contact your system administratior.", vbCritical, "Restricted Access!"
        Application.Quit
    End If
Exit_cmdLogIn_Click:
    Exit Sub
Err_cmdLogIn_Click:
    MsgBox Err.Description, , " db1"
    Resume Exit_cmdLogIn_Click
End Sub
 
Else
MsgBox "Password Invalid. Please Try Again!", vbInformation, "Invalid Entry"
With rst
.AddNew
![ClientID] = Me.Combo0
.Update
.Close
End With
MsgBox "Log In Successful"
End If

It appears that your "Log In Successful" and rst editing is done in the "Else" statement, meaning it happens when the user has not successfully logged in.

I believe your code should read:

With rst
.AddNew
![ClientID] = Me.Combo0
.Update
.Close
End With
MsgBox "Log In Successful"
Else
MsgBox "Password Invalid. Please Try Again!", vbInformation, "Invalid Entry"
End If
 
Here is a cleaner version of the code for you to look at, you may be able to follow it easier than the current one. I corrected something at the end for you, in your code the msgbox "Incorrect, please try again!" comes up, and then "You don't have access to the database!" comes up. So if they are wrong 3 times, they get 2 messageboxes in a row.

This code gives them "Try Again" or "You don't have access" message.

Hope this is of help to you.
 

Attachments

Here is a cleaner version of the code for you to look at, you may be able to follow it easier than the current one. I corrected something at the end for you, in your code the msgbox "Incorrect, please try again!" comes up, and then "You don't have access to the database!" comes up. So if they are wrong 3 times, they get 2 messageboxes in a row.

This code gives them "Try Again" or "You don't have access" message.

Hope this is of help to you.


THANK YoU! THANK YOU! THANK YOU!

That worked perfectly :D
 
Glad it worked for you!

If you have any other problems, let us know.
 

Users who are viewing this thread

Back
Top Bottom