I have been researching this for a while and I still haven’t been able to solve the problem. I have developed a front end (in MS Access using VBA) that allows users to easily enter, view, and interact with data stored in our SQL Server.
Everything is working well except that the user's passwords expire every 60-ish days and they have no way to update their password through the MS Access front end and I am sick and tired of manually updating passwords.
I have created some code that allows users to change their password if the password hasn’t already expired, but once the password has expired we are SOL and have to manually change it in the back end.
I think the problem is that when the password hasn’t expired the user can still successfully connect to the SQL Server and execute the stored procedure that will change their password. However, once the password has expired, they can no longer actually connect to the server to execute the stored procedure to change their password. Any ideas on how to solve this problem? All the passwords are going to expire soon and I would LOVE to not manually update all the passwords.
Here is an example of the code that I am working on. It is full of garbage and doesn’t work, but I think it may be in the right direction.
Option Compare Database
Private Sub ChangePWbutton_Click()
On Error GoTo ErrHandler
Dim cnComments As New ADODB.Connection
Dim strCS As String
Dim P As String
Dim Rsx As ADODB.Recordset
'Set up the connection string
strCS = "Provider=SQLOLEDB;" _
& "Server=IPaddressHere\SQL_2005;" _
& "Database=" + DBselect.Value + ";" _
& "User ID=" + Uname.Value + ";" _
& "Password=" + pWord.Value + ";" _
& "MARS Connection=True;"
cnComments.Open strCS
If cnComments.State = adStateOpen Then
MsgBox "it is open Place 1"
End If
'P = "sp_password '" & pWord.Value & "', '" & NewPW.Value & "', '" & Uname.Value & "'"
'Set Rsx = cnComments.Execute(P)
ErrHandler:
Select Case Err.Number
Case -2147467259
If cnComments.Errors.Count > 1 Then
Select Case cnComments.Errors(1).NativeError
Case 18463 To 18468, 18487 To 18488
MsgBox "The password must be changed. Password expired."
If cnComments.State = adStateOpen Then
MsgBox "it is open place 2"
End If
'cnComments.Open strCS, bragado_l, Accenture1*
P = "sp_password '" & pWord.Value & "', '" & NewPW.Value & "', '" & Uname.Value & "'"
Set Rsx = cnComments.Execute(P)
'strNewPassword = ChangePassword() 'a function you create
'If Len(strNewPassword) Then
'Con.ConnectionString = strConnectionString & ";User ID=" & strUser & ";Password=" & strNewPassword & ";Old Password=" & strPassword
'Resume ExitProc
'Else
' QuitProgram
'End If
End Select
End If
Case Else
VBA.MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, "Unexpected error"
End Select
'Resume ExitProc
'Resume
End Sub