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
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