What password do you want to change? If you mean a network password, I can't help you. But if you mean an Access User Account password, do the following:
1. Create a small form to prompt the user for a new password.
2. Set the following Form properties:
Caption: Change Password
Scroll Bars: Neither
Record Selectors: No
Navigation Buttons: No
Auto Center: Yes
Modal: Yes
Border Style: Dialog
Min Max Buttons: None
3. Add unbound text boxes for Old Password, New Password, and Verify Password. Name them txtOldPassword, txtNewPassword, and txtVerifyPassword, respectively.
4. Set the Input Mask for each of these to "PASSWORD".
5. Add OK and Cancel buttons.
6. Create the following event procedures:
Code:
Private Sub cmdCancel_Click()
DoCmd.Close
End Sub
Private Sub cmdOK_Click()
Dim wsp As Workspace
If Nz(txtNewPassword) <> Nz(txtVerifyPassword) Then
txtVerifyPassword.SetFocus
Beep
MsgBox "Verify the new password by retyping it in the Verify box and clicking OK.", vbInformation
Exit Sub
End If
Set wsp = DBEngine.Workspaces(0)
On Error GoTo ErrorHandler
wsp.Users(CurrentUser).NewPassword Nz(txtOldPassword), Nz(txtNewPassword)
DoCmd.Close
ErrorExit:
Set wsp = Nothing
Exit Sub
ErrorHandler:
If Err = 3033 Then
txtOldPassword.SetFocus
Beep
MsgBox "The password you entered in the Old Password box is incorrect." _
& vbCrLf & vbCrLf _
& "Please enter the correct password for this account.", _
vbInformation
Resume ErrorExit
End If
Err.Raise Err.Number
End Sub
7. Save the form with the name Change Password
8. Place a Change Password button on your original form.
9. Add the following event procedure to that form:
Code:
Private Sub cmdChangePassword_Click()
DoCmd.OpenForm "Change Password", , , , , acDialog
End Sub
Note: If you are using Access 2000, make sure you set a reference to Microsoft DAO 3.6 Object Library.