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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
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

Scott McDaniel (Microsoft Access MVP - EE MVE )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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.