D
Darren
In a secure database, I wish to create a form that users can use to change
their passwords. I created a standard form with three unbound fields and a
command button. The intention was that the user would enter their old
password in field 1, the new password in field 2 then confirm it in field 3.
They would then click on the "Change Password" command button and voila!
The result was not what I wanted. All I got was an error message regards
objects not defined etc (at the first Dim statement). I checked the
helpfile re examples of cose used for changing passwords and even by copying
and pasting, they too failed with the same error.
Below is the code I used:
Sub Change_Password()
Dim CrntUser As User
Dim OldPW As String
Dim NewPW As String
Dim ConfPW As String
Set CrntUser = CurrentUser
OldPW = Me.txtOldPassword
NewPW = Me.txtNewPassword
ConfPW = Me.txtConfirmPassword
' Check that new password and confirmation matches
If NewPW <> ConfPW Then
MsgBox "The confirmation of password does not match, please
re-enter", vbExclamation + vbOKOnly, "Password Error - No Match"
Me.txtNewPassword = ""
Me.txtConfirmPassword = ""
DoCmd.GoToControl "Me.txtNewPassword"
Exit Sub
End If
' Check that the new password is greater that 6 characters
If Len(NewPW) < 6 Then
MsgBox "Your password must be a minimum of 6 characters long, please
re-enter", vbExclamation + vbOKOnly, "Password Error - Too Short"
Me.txtNewPassword = ""
Me.txtConfirmPassword = ""
DoCmd.GoToControl "Me.txtNewPassword"
Exit Sub
End If
' Check that the password does not exceed 14 characters
If Len(NewPW) > 14 Then
MsgBox "Your password can be no more than 14 characters long, please
re-enter", vbExclamation + vbOKOnly, "Password Error - Too Long"
Me.txtNewPassword = ""
Me.txtConfirmPassword = ""
DoCmd.GoToControl "Me.txtNewPassword"
Exit Sub
End If
CrntUser.NewPassword OldPW, NewPW
MsgBox "Password change successful", vbInformation + vbOKOnly,
"Change Confirmed"
End Sub
Any ideas?
Regards
Darren
their passwords. I created a standard form with three unbound fields and a
command button. The intention was that the user would enter their old
password in field 1, the new password in field 2 then confirm it in field 3.
They would then click on the "Change Password" command button and voila!
The result was not what I wanted. All I got was an error message regards
objects not defined etc (at the first Dim statement). I checked the
helpfile re examples of cose used for changing passwords and even by copying
and pasting, they too failed with the same error.
Below is the code I used:
Sub Change_Password()
Dim CrntUser As User
Dim OldPW As String
Dim NewPW As String
Dim ConfPW As String
Set CrntUser = CurrentUser
OldPW = Me.txtOldPassword
NewPW = Me.txtNewPassword
ConfPW = Me.txtConfirmPassword
' Check that new password and confirmation matches
If NewPW <> ConfPW Then
MsgBox "The confirmation of password does not match, please
re-enter", vbExclamation + vbOKOnly, "Password Error - No Match"
Me.txtNewPassword = ""
Me.txtConfirmPassword = ""
DoCmd.GoToControl "Me.txtNewPassword"
Exit Sub
End If
' Check that the new password is greater that 6 characters
If Len(NewPW) < 6 Then
MsgBox "Your password must be a minimum of 6 characters long, please
re-enter", vbExclamation + vbOKOnly, "Password Error - Too Short"
Me.txtNewPassword = ""
Me.txtConfirmPassword = ""
DoCmd.GoToControl "Me.txtNewPassword"
Exit Sub
End If
' Check that the password does not exceed 14 characters
If Len(NewPW) > 14 Then
MsgBox "Your password can be no more than 14 characters long, please
re-enter", vbExclamation + vbOKOnly, "Password Error - Too Long"
Me.txtNewPassword = ""
Me.txtConfirmPassword = ""
DoCmd.GoToControl "Me.txtNewPassword"
Exit Sub
End If
CrntUser.NewPassword OldPW, NewPW
MsgBox "Password change successful", vbInformation + vbOKOnly,
"Change Confirmed"
End Sub
Any ideas?
Regards
Darren