A
AccessIM
I borrowed the following code for creating a form that the user's can set
their own password on a newly secured database. I have many users set up
with no password and would like to give them the ability to change it
themselves but when I test the form I get an "Error 94 Invalid use of Null"
message.
Here is the code on the form in the On_Click event of a button:
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 "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
And here is the code in the Module:
'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 read threads about SetPassword but didn't see any supporting code samples.
Could someone please tell me where I am going wrong? Thank you so much.
their own password on a newly secured database. I have many users set up
with no password and would like to give them the ability to change it
themselves but when I test the form I get an "Error 94 Invalid use of Null"
message.
Here is the code on the form in the On_Click event of a button:
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 "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
And here is the code in the Module:
'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 read threads about SetPassword but didn't see any supporting code samples.
Could someone please tell me where I am going wrong? Thank you so much.