Private Sub cmdChangePassword_Click()
On Error Resume Next
If Me!txtNewPassword = Me!TxtConfirmNewPassword Then
ChangeUserPassword DBEngine(0).UserName, _
Me!txtCurrentPassword, Me!txtNewPassword
If (Err = 0) Then
MsgBox "Your Password was changed.", _
vbOKOnly + vbInformation, _
"Password Change"
DoCmd.Close acForm, Me.Name
Else
MsgBox "Your password could not be changed." & _
vbCrLf & vbCrLf & _
Error & Err.Number & _
vbCrLf & Err.Description, _
vbOKOnly + vbExclamation, _
"Password Change"
End If
Else
MsgBox "The new passwords do not match."
End If
End Sub
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
--
Westeral
The form had three fields: OldPassword, NewPassword and
VerifyNewPassword. It also has two buttons (the code for the click
events is shown below. To display stars rather than the password on
the screen set the Input Mask to Password
' Declarations:
Option Compare Database 'Use database order for string comparisons
Option Explicit
Dim OldPasswordVar As String
Dim NewPasswordVar As String
Dim VerifyVar As String
' Code for Click Event of OK button
Sub OKButton_Click ()
On Error GoTo Err_OKButton_Click
If IsNull(Me!OldPassword) Then
OldPasswordVar = ""
Else
OldPasswordVar = Me!OldPassword
End If
If IsNull(Me!newpassword) Then
MsgBox "Please enter a New Password"
Me!newpassword.SetFocus
Exit Sub
Else
NewPasswordVar = Me!newpassword
End If
If IsNull(Me!Verify) Then
MsgBox "Please verify New Password"
Me!Verify.SetFocus
Exit Sub
Else
VerifyVar = Me!Verify
End If
If NewPasswordVar = VerifyVar Then
DBEngine.Workspaces(0).Users(CurrentUser()).NewPassword
OldPasswordVar, NewPasswordVar
MsgBox "Password changed successfully"
DoCmd Close
Else
MsgBox "Please re-enter new password and verify"
Me!newpassword.SetFocus
Exit Sub
End If
Exit_OKButton_Click:
Exit Sub
Err_OKButton_Click:
Beep
If Err = 3001 Then
MsgBox "You have typed an invalid New Password." & _
vbCrLf & "The maximum length for a password is 14 characters."
ElseIf Err = 3033 Then
MsgBox "Incorrect Old Password. Please try again."
Else
MsgBox Error$ & Err
End If
Resume Exit_OKButton_Click
End Sub
' Code for Click Event of the Cancel Button:
Sub CancelButton_Click ()
DoCmd Close
End Sub
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
Disclaimer: Any code or opinions are offered here as is. Some of that
code has been well tested for number of years. Some of it is untested
"aircode" typed directly into the post. Some may be code from other
authors. Some of the products recommended have been purchased and
used by the author. Others have been furnished by their manufacturers.
Still others have not been personally tested, but have been
recommended by others whom this author respects.
You can thank the FTC of the USA for making this disclaimer necessary.
"Westeral" <West...@discussions.microsoft.com> wrote in message
news:03D0869C-E68E-462A...@microsoft.com...
"Arvin Meyer [MVP]" wrote:
> .
>