You are here:

Using MS Access/change password at first login


QUESTION: Hi my question is how I can force a user to change his password at first login

ANSWER: Hi Akshee,

Many thanks for the question.

Before I can answer this, I need some more information.  

What version of Microsoft Access are you using?
Are you using the Microsoft Access security to set up the passwords?

If not, tell me about how the user logs in, I am presuming a form, with a text box and a login button.  I also need to know where the password is stored, i.e. a table, the name of the table and the name of the field.

If you could let me know ALL of the above information, I am sure I can assist.

Looking forward to hearing from you.

---------- FOLLOW-UP ----------

 Change Password Form
Change Password Form  
QUESTION: Access version is 2007, and no access is security set up.My login form has a combo box with a text field and the password is stored in a table called "employee" with field as follows: "Name", "Password","ChangeonLogon" is a field with checkbox, "DateLastLogin", "DatePwdChange", "New Password", "New Password 2"

Hi Akshay,

Many thanks for the extra info, and for the image, they will assist greatly.

You will need to write a bit of code to achieve this. I have tried to keep it to a minimum

To do what you ask, try the following:

I am presuming you have previously assigned a username and password,and these are the first two fields in your table.

I am not sure if the four fields you show on the form on your image are bound to the underlying table or not.  If they are, then make them unbound and leave them there, as we will use them.  Then add all the fields linked to the table back in (we will be hiding these, so do not worry about formatting etc).  

If your form/fields are not linked to the underlying table, then link your logon form to the table, you may need to recreate the form.  Add all the fields but hide them all (right click > properties > Format tab > Visible = No) and re-add your combo box choosing to 'Find a record on my form.....', this will allow you to easily refer to these fields with the code.

You may wish to check everything is working okay first, then hide your fields.

Note: You do not require the two fields New Password and and New Password 2

Add the following code to the On Click event for the logon button (right click on the combo box, properties, event tab, place your cursor next to 'On Click' If there is Embedded Macro written, here, then do the following:

on the Design Toolbar, click on 'Convert Form's Macros to Visual Basic, click Ok to select the default options, this will change the Macro to code.

> Click on the button with the three dots. This will open the coding window, with code similar to the following: (Note, if your button already does something i.e. goes to another form, then add the code, just after the first line of code:

Private Sub Command40_Click()

End Sub

Add the following code in between the above two lines of code:

Note: I this is what I have called the unbound fields

ubDefaultPW - the users original/actual password.
ubNewPW -

If you name your fields the same, then the code below should work.

'***Start Code
If Me!ChangeOnLogon = 0 And Me!ubDefaultPW = Me!Password Then
'Checks to see if the changed password is the same for both fields and if it is adds it to the field that stores that password in the table.
   If Me!ubNewPW = Me!ubCheckPW Then
       Me!Password = Me!ubNewPW
       Me!DateLastLogin = Date
       Me!DatePwdChange = Date
       Me!ChangeOnLogon = -1
'Clears the fields if the passwords do not match
       MsgBox "Your new passwords do not match, please try again"
       Me!ubNewPW = ""
       Me!ubCheckPW = ""
       Exit Sub
   End If

'Normal login, i.e. not first time.  Checks to see if password is correct.
   If Me!ubDefaultPW <> Me!Password Then
       MsgBox "Your password or username is incorrect, please try again"
       Me!ubDefaultPW = ""
       Exit Sub
   End If

End If

'Put the original code you had here.

'****end of code.

You will also need to add code, to the After Update Event for ubDegaultPW

Add between the two lines of code:

'****Start Code

If Me!ubDefaultPW <> Me!Password Then
MsgBox "Oops Sorry. wrong password please try again"
Me!ubDefaultPW = ""
Exit Sub
End If
If Me!ChangeOnLogon = 0 Then
MsgBox "Please change your password"
End If

'****End Code

I hope this is all reasonably easy to understand.  If you have problems, let me know exactly where you got up to, and any error messages you may have had.  

Using MS Access

All Answers

Answers by Expert:

Ask Experts


Julie Misson


My area of expertise is Microsoft Access 2000-2007. I have been building microsoft databases for the past twelve years. I would be competent in answering questions from novice Access 2000 users to the more advanced including VBA. If I cannot help, I am more than likely be able to point you to websites that can.


I have a Microsoft Access business where I build database for small businesses. These are usually one off designs, where there is no off the shelf software avaliable to meet the business needs. I also teach Microsft Access to beginners. I am the owner of the website.

Self taught in Microsoft Access. Have done some units in normalisation and SQL, but most of what I know I have learnt from books originally and more recently the Internet.

©2017 All rights reserved.