Here is the code I'm using on a change PW form....
Code:
Private Sub ConfirmNewPassword_AfterUpdate()
'moves the focus so I can clear the text boxes later
DoCmd.GoToControl "CurrentPassword"
If Me!ConfirmNewPassword = Me!NewPassword Then
'update to the new password and tell user
CurrentDb.Execute "UPDATE SUtility SET SUtility.PW = '" & Me!ConfirmNewPassword & "'"
MsgBox "Password has been changed. This is a positional password. Be sure to share the new password with your alternate in your changeout notes."
Else
MsgBox "Failed. Password has not been changed."
End If
'clear the text boxes and disable
Me!NewPassword = ""
Me!ConfirmNewPassword = ""
Me!CurrentPassword.Enabled = False
Me!ConfirmNewPassword.Enabled = False
DoCmd.Close
End Sub
Private Sub CurrentPassword_AfterUpdate()
'if the user knows the existing password, allow a change
If Me.CurrentPassword.Value = DLookup("PW", "SUtility") Then
Me!NewPassword.Enabled = True
Me!ConfirmNewPassword.Enabled = True
Else
Me!NewPassword.Enabled = False
Me!ConfirmNewPassword.Enabled = False
MsgBox "Password is incorrect"
End If
End Sub
Private Sub SubmitNewPW_Click()
On Error GoTo Err_SubmitNewPW_Click
DoCmd.RunCommand acCmdRefresh
Exit_SubmitNewPW_Click:
Exit Sub
Err_SubmitNewPW_Click:
MsgBox Err.Description
Resume Exit_SubmitNewPW_Click
End Sub
Everything works just fine except once I push ok on the msgbox "Password has been changed. This is a positional password. Be sure to share the new password with your alternate in your changeout notes."
I get a runtime error 2164 "Cant disable a control while it has the focus"
This code works fine in 2010 but when I run DB with 2007 or later i get the runtime error. In fact the code works fine and does everything its supposed to even changes the password in all versions of Access but in 2007 or later I get the runtime error.
What can I do to keep from getting the error box and maintaining a working code for all versions of Access?