Change password on first login

I have the following code in an onclick event of a command button on a login form but want to alter it so the user has to change their password with the first login.  How can this be done?

Here's the current code:

Private Sub cmdLogin_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"
        Exit Sub
    End If
'Check to see if data is entered into the Password combo box
    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
            MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
        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", "tblEmployees", "[ID]=" & Me.cboEmployee.Value) Then
        myempid = Me.cboEmployee.Value

    Dim rs As DAO.Recordset
        Set rs = CurrentDb.OpenRecordset("LOCALtblCurrentUser")

        rs!EmpName = Me.cboEmployee.Column(1)
        rs!EmpN = Me.cboEmployee.Column(0)
        rs!Level = Me.txtLevel
        rs!Initials = Me.txtInitials
        rs!Approver = Me.txtApprover
'Close logon form and open splash screen
    DoCmd.Close acForm, "frmLogin", acSaveNo
    DoCmd.OpenForm "frmMainMenu"
        MsgBox "Password Invalid. Please Try Again", vbCritical + vbOKOnly, "Invalid Entry!"
    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!"
    End If
End Sub
Who is Participating?
Scott McDaniel (Microsoft Access MVP - EE MVE )Connect With a Mentor Infotrakker SoftwareCommented:
I usually add a generic password when the user is added, and then check that each time. If the password = [generic password], then I require the user to change.

So if my generic password is "changeme", then when I add user ScottMcd I set that user's password to "changeme". When my login form opens, I check the user's password. If it's "changeme", then I show a message requiring them to change it, and show the appropriate forms to allow them to enter their new password.
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
What is the trigger/flag that this is the first login?

What method will you use to allow the user to change their password?

How I handle this is to set the flag/trigger (ie: date password changed to 1/1/1901)  that controls if the password has expired (ie: X days since last changed) . This will force the user to change their password using a change password form.

You could add a yes/no field to the user table for first log on.

'Close logon form and open splash screen
    DoCmd.Close acForm, "frmLogin", acSaveNo
   ' check to see if this is the first login and need to change the password

     If IsFirstLogon then 
        DoCmd.OpenForm "frmChangePassword", , , , ,acDialog

     End If

   DoCmd.OpenForm "frmMainMenu"

Open in new window

Boyd (HiTechCoach) Trimmell, Microsoft Access MVPConnect With a Mentor Commented:
One advantage to adding a yes/no field to the user table for first login is that it can be used to force a user to change their password.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.