VBA to Retrieve Query SQL

CT Witter

MrExcel MVP
Joined
Jul 7, 2002
Messages
1,212
I have the following code to retrieve the SQL from a specified query. The problem is that it can only run once and then locks up the db so I can't run again without closing access.

Is there a better way to retrieve the SQL of a query?

Thanks,
CT

Code:
Sub ModifyQuery(strDBPath As String, _
                strQryName 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=" & strDBPath
   
   Set cmd = New ADODB.Command
   ' Get the query from the Procedures collection.
   Set cmd = catDB.Procedures(strQryName).Command
   
   ' Get the query SQL.
   Debug.Print cmd.CommandText
   Application.RefreshDatabaseWindow
   Set cmd = Nothing
   Set catDB = Nothing
   
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
This sounds a little like something I was fiddling with in my spare time a litte while ago. Building my own interface that lets me manipulate fields within a table. I was gunning for the same sort of interface (click and select, move up, move down, change field types) as you'd get from Access itself, I just didn't want the users IN the table itself.

Thinking about it, I'd assume somebody has already built something like this.

Mike
 
Upvote 0

Forum statistics

Threads
1,221,902
Messages
6,162,724
Members
451,782
Latest member
LizN

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top