Results 1 to 2 of 2
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Refresh ODBC Connection with new UserID and Password

    How can I refresh an ODBC connection with a new User ID and Password? I cannot delete the table and re-link it due to primary key requirements. Is there a way to simply refresh the tables programmatically and give the ODBC connection a new/different User ID and Password?

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Solved...

    Code:
    Function funRefreshODBC(strHSLCUser As String)
    On Error GoTo ErrorHandler
        Dim DAOdb As DAO.Database
        Dim tblDef As DAO.TableDef
        Dim rs As DAO.Recordset
        Dim strConnectOld As String, mySQL As String, strUserID As String, strPass As String
        
        Set DAOdb = CurrentDb
        
        mySQL = "SELECT * FROM tblODBCConnections WHERE [ODBC_Database] = 'SAPRD';"
        Set rs = CurrentDb.OpenRecordset(mySQL)
        rs.MoveLast
        rs.MoveFirst
        
        strUserID = DLookup("UserSAPRD", "tblUsers", "[UserID] = '" & strHSLCUser & "'")
        strPass = DLookup("UserSAPRDPass", "tblUsers", "[UserID] = '" & strHSLCUser & "'")
        
        Do While Not rs.EOF
            Set tblDef = DAOdb.TableDefs(rs![TableName])
            tblDef.Connect = "ODBC; DSN=" & rs![ODBC_DSN] & "; DBQ=SAPRD; UID=" & strUserID & "; PWD=" & strPass
            tblDef.RefreshLink
            rs.MoveNext
        Loop
        rs.Close
        
        mySQL = "SELECT * FROM tblODBCConnections WHERE [ODBC_Database] = 'FDOPRD';"
        Set rs = CurrentDb.OpenRecordset(mySQL)
        rs.MoveLast
        rs.MoveFirst
        
        strUserID = DLookup("UserFDOPRD", "tblUsers", "[UserID] = '" & strHSLCUser & "'")
        strPass = DLookup("UserFDOPRDPass", "tblUsers", "[UserID] = '" & strHSLCUser & "'")
        
        Do While Not rs.EOF
            Set tblDef = DAOdb.TableDefs(rs![TableName])
            tblDef.Connect = "ODBC; DSN=" & rs![ODBC_DSN] & "; DBQ=FDOPRD; UID=" & strUserID & "; PWD=" & strPass
            tblDef.RefreshLink
            rs.MoveNext
        Loop
        rs.Close
    ResumeFunction:
        DoCmd.SetWarnings True
        DoCmd.Hourglass False
        Exit Function
        
    ErrorHandler:
        MsgBox Err.Number & " - " & Err.Description, vbCritical, "Critical Error"
        GoTo ResumeFunction
    End Function

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

Similar Threads

  1. "Automatically" populate UserID & Password for ODBC
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 06-02-2011, 11:18 AM
  2. ODBC 32 to 64 Bit connection error
    By mgmtexecit in forum Reports
    Replies: 0
    Last Post: 03-30-2011, 10:06 AM
  3. ODBC 32 to 64 Bit connection error
    By mgmtexecit in forum Access
    Replies: 1
    Last Post: 03-30-2011, 10:05 AM
  4. Virtual Password-Protected Connection
    By marianne in forum Sample Databases
    Replies: 6
    Last Post: 02-18-2011, 10:41 AM
  5. ODBC connection
    By avicenna in forum Import/Export Data
    Replies: 2
    Last Post: 08-02-2010, 02:33 AM

Tags for this Thread

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