Change current sql user password from Access Form

  • I am trying to change the current sql users password via an Access form.  I have a form with the following onClick() event code -- 

    Private Sub Command10_Click()

      Dim stDocName As String

      Dim OldPassword_field As String

      Dim NewPassword_field As String

        

       [Forms]![f_ChangePassword]![OldPassword_field].SetFocus

       OldPassword_field = [Forms]![f_ChangePassword]!   [OldPassword_field].[Text]

       [Forms]![f_ChangePassword]![NewPassword_field].SetFocus

       NewPassword_field = [Forms]![f_ChangePassword]![NewPassword_field].[Text]

       stDocName = "q_ChgPwd"

       DoCmd.OpenQuery stDocName, acNormal, acEdit

       

    End Sub

    The "q_ChgPwd" is a pass-thru query with code below

    Exec sp_password oldPassword_Field , NewPassword_Field

    I keep getting an error message that the oldPassword doesn't match and the password hasn't changed.  It seems to me that the pass-thru query is not receiving the text values from the form.  Does anyone have some suggestions as to how I might get this to work?

    Thank you. 

  • Just some possible stuff:

    This only works if this is a SQL Server authenticated id.

    You might need quotes around the old and new password strings so that the command resolves to

    exec sp_password "oldpassword","newpassword"

     rather than

    exec sp_password oldpassword,newpassword

    This form of the sp_password only works if you're changing the id you're logged in as, so if the app logs in as someone else under the covers, it will give you the 'old password doesn't match' error. 


    And then again, I might be wrong ...
    David Webb

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply