Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the ODBC Link in VBA Fires the query on more than one DB

Status
Not open for further replies.

BigOrangeMonkey

Programmer
Aug 27, 2002
26
0
0
GB
Hi,

I have the following code to change the connection string on a Pass-Through query to point to a different database, when the connection string is changed the query is fired off on both the old connection and the new one, the problem is I am not executing the query!!

i.e.
The query is to Truncate TableA on Database1,
I change the connection to database2,
at the line
"Set catdb.Procedures(strQryName).Command = cmd" where cmd now points to database2
TableA is truncated on Database1 and Database2, Any Ideas why this happens?

Heres the code :

Code:
Sub ModifyQuery(strQryName As String, _
                strConnection As String)
   Dim catdb As ADOX.Catalog
   Dim cmd   As ADODB.Command

   Set catdb = New ADOX.Catalog
   ' Open the Catalog object.
   catdb.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & Application.CurrentProject.FullName

   Set cmd = New ADODB.Command
   'Get the query from the Procedures collection.
   Set cmd = catdb.Procedures(strQryName).Command
   ' Update the query's SQL statement.
    With cmd
        .Properties("Jet OLEDB:ODBC Pass-Through Statement") = True
        .Properties("Jet OLEDB:Pass Through Query Connect String") = strConnection
    End With

   'Save the updated query.
   Set catdb.Procedures(strQryName).Command = cmd

   Set catdb = Nothing
End Sub

Thanks,
Steve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top