Share via

ODBC connection string password

Anonymous
2013-01-02T18:12:44+00:00

We are required to change our ODBC connection password on a periodic basis.  How do I modify the password that is stored in the MSysObjects table so I don't have to drop and reconnect to my tables in all of my Access 2010 databases everytime my password changes?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2013-01-03T22:39:19+00:00

    It is not recommended to modify data in the MSysObjects table, instead use the TableDef object.

    Try something like this:

    Public Function UpdatePassword(sOldPasswood As String, sNewPassword As String)

    On Error GoTo PROC_ERR

        If Len(sOldPasswood) <> 0 And Len(sNewPassword) <> 0 Then

            Dim tdf As DAO.TableDef

            Dim qdf As DAO.QueryDef

            Dim sConnect As String

            ' Refresh Access Linked Tables

            For Each tdf In CurrentDb.TableDefs

                If InStr(tdf.Connect, sOldPasswood) Then

                    tdf.Connect = Replace(tdf.Connect, "PWD=" & sOldPasswood, "PWD=" & sNewPassword)

                    tdf.RefreshLink

                End If

            Next

            ' Refresh Access PassThrough Queries

            For Each qdf In CurrentDb.QueryDefs

                If InStr(qdf.Connect, sOldPasswood) Then

                    Call Replace(qdf.Connect, "PWD=" & sOldPasswood, "PWD=" & sNewPassword)

                End If

            Next

        Else

            MsgBox "An Old Password and New Password are required!", vbOKOnly + vbCritical, "Error"

        End If

    PROC_EXIT:

        Exit Function

    PROC_ERR:

        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure UpdatePassword"

        Resume PROC_EXIT

        Resume

    End Function

    'Updated code

    Was this answer helpful?

    0 comments No comments
  2. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2013-01-03T20:23:57+00:00

    Are you connecting to SQL Server? If so, I would use Doug Steele's code to set the connection property http://www.accessmvp.com/DJSteele/DSNLessLinks.html.

    Was this answer helpful?

    0 comments No comments