Results 1 to 5 of 5
  1. #1
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185

    Question Code for change PW frm not working(ish)

    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?

  2. #2
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Be sure to set the focus to a specif control that you are NOT disabling (.Enabled = False). I find this to be true in all version of Access.

  3. #3
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    I did. First part of the code.....

    DoCmd.GoToControl "CurrentPassword"


    But still getting error.....

  4. #4
    Desstro's Avatar
    Desstro is offline Competent Performer
    Windows XP Access 2010 (version 14.0)
    Join Date
    May 2010
    Posts
    185
    oops...I apologize, I see where Im wrong, I need to set the focus on "NewPassword" Solved. Thanks.

  5. #5
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Great job.

    Glad to hear you got it solved.

    Thanks for the update.

    PS:
    By set focus I was referrfng to this: Me.NewPassword.SetFocus

Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA Code Not working
    By jo15765 in forum Programming
    Replies: 12
    Last Post: 12-03-2010, 04:01 PM
  2. DLookup code not working
    By lukekelly in forum Programming
    Replies: 9
    Last Post: 06-15-2010, 06:08 AM
  3. VB code not working
    By cwwaicw311 in forum Programming
    Replies: 17
    Last Post: 04-26-2010, 07:02 PM
  4. VBA Code for working with IE
    By smikkelsen in forum Programming
    Replies: 3
    Last Post: 04-15-2010, 01:05 AM
  5. Replies: 4
    Last Post: 05-12-2009, 01:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums