W
Westeral
I am trying to create a simple password manager database for users at my work
site so that they do not keep passwords taped to the screen or in their desk
drawer. The database will be standalone and have a password. When they first
open the database they will change their password. The problem is the code I
have to change it will not work. It runs into a permissions problem even
though I have set the default to open exclusively. The code for the button
and module it uses follow. What am I doing wrong? (I can send the entire
database if needed although it is not totally finished). The database will
be a standalone on each users computer. Thanks in advance.
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
site so that they do not keep passwords taped to the screen or in their desk
drawer. The database will be standalone and have a password. When they first
open the database they will change their password. The problem is the code I
have to change it will not work. It runs into a permissions problem even
though I have set the default to open exclusively. The code for the button
and module it uses follow. What am I doing wrong? (I can send the entire
database if needed although it is not totally finished). The database will
be a standalone on each users computer. Thanks in advance.
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