Graham,
Sorry, I mistyped the message I sent in the post.
However, I did not mistype the coding.
I copied and pasted it exactly.
I've deleted the test database and started again anyway.
The steps I've taken are as follows: (Note: The code you see below is copied
directly from the database)
I created a number of UserNames, some with passwords, some not, using the
User level security wizard.
I created a new form with the name "Form1",
In this I created 3 text boxes vertically aligned with the names, top to
bottom -
txtCurrentPassword,
txtNewPassword,
txtConfirmNewPassword.
I then created 2 cmd buttons named cmdChangePassword, and cmdCancel
respectively.
In the cmdChangePassword I pasted the following under the On Click
(selecting Code Builder as the option instead of Macro or Expression):
Private Sub cmdChangePassword_Click()
On Error Resume Next
If Me!txtNewPassword = Me!txtConfirmNewPassword Then
ChangeUserPassword DBEngine(0).UserName, _
Me!txtOldPassword, Me!txtNewPassword
If (Err <> 0) Then
MsgBox "Error " & Err.Number & vbCrLf & _
Err.Description, vbOKOnly + vbExclamation, _
"Could not change password"
End If
Else
MsgBox "The new passwords do not match."
End If
End Sub
I then added the appropiate code under the Cancel button.
I then created a new module with the name Module1.
In this Module I pasted the following:
'Change a user's password
Public Sub ChangeUserPassword(strUser As String, _
strOldPassword As String, strNewPassword As String)
Dim wrk As DAO.Workspace
Dim usr As DAO.User
Set wrk = DBEngine(0)
Set usr = wrk.Users(strUser)
'Change the password
usr.NewPassword strOldPassword, strNewPassword
Set usr = Nothing
Set wrk = Nothing
End Sub
I then saved it all.
I then reopened it and opened Form1.
I entered the current and new passwords in each of the 3 boxes and clicked
the Change password button as above.
It gave me the error message 2465. "Microsoft Access can't find the field
'txtOldPassword' referred to in your expression".
Hope I done it properly.
Thanks,
Kevin