Issue running Access SQL queries - unable to wait for one query to finish before starting the next one

MK123

New Member
Joined
Apr 1, 2011
Messages
1
Hi,

I have developed a model in Excel 2007 that uses an ADODB connection to run a number of queries in Access. In testing it I have found out that the VBA code won't wait for one query to finish before starting the next one - which is creating errors in the model as some run much slower than others. I've read a lot today about asynchronous processes but I have been unable to identify how to make my VBA code wait for each query to finish. I really want to avoid adding an arbitrary time delay.

Below is the code i'm using to run queries. Does anyone know of any ways to get around this problem? Any help anyone can offer would be greatly appreciated.

Thanks


Public Sub ExecSQL(ByVal strQuery As String)
Dim cmd As New ADODB.Command
cmd.ActiveConnection = conn
cmd.CommandText = strQuery
cmd.CommandType = adCmdText
cmd.Execute

End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Using querytables?
add .refresh backgroundquery=false to make it wait till the query is done before moving on.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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