Relink pass through queries

thr33xx

Registered User.
Local time
Today, 14:56
Joined
May 11, 2011
Messages
43
I am attempting to relink a handful of pass through queries. I have found the following codes to relink the queries, though I am unsure of how to use them. Could somemone provide some insight as to how I would get these queries updated using either of the codes below? More specifically, where do I place these codes? Into the query themselves?

Code:
[INDENT]Dim qdf As dao.QueryDef 
    Dim dbs As dao.Database 

Set dbs = CurrentDb 

 create connection string 
Dim strConnect As String 
        strConnect = "ODBC;DRIVER={SQL Native Client}" _ 
                & ";SERVER=server_name" _ 
                & ";DATABASE=database_name" _ 
                & ";UID=my_user" _ 
                & ";Trusted_Connection=Yes" & ";" 

For Each qdf In dbs.QueryDefs 

    If qdf.Type = dbQSQLPassThrough Then 
        qdf.Connect = strConnect 
    End If 

Next qdf 

dbs.Close  [/INDENT]



Code:
[INDENT]Sub RelinkSQLQueries()
Dim db As Database
Set db = CurrentDb
Dim qdef As QueryDef
Dim constr As Variant
constr = DLookup("ConnectionString", "tblConnections", "Active = True")
For Each qdef In db.QueryDefs
If InStr(qdef.Connect, "ODBC") Then
qdef.Connect = constr
End If
Next
MsgBox "Re link completed"
End Sub[/INDENT]
 
Solved!

Had to update each pass through query's ODBC Connect Str in properties.
 

Users who are viewing this thread

Back
Top Bottom