title: ADODB wait for query to complete before refreshing a different connection
body: <p>I have a table in excel that is populated through a connection to an Access database. I am trying to write a macro that allows you to delete individual rows from this table. I use an ADODB connection to pass the delete command to Access, which works fine. However, at the end of the macro I want to refresh the table in excel so that, upon completion of the macro, the deleted record will no longer appear in that table.</p>
  
  <p>I have already set backgroundquery = False on the connection that populates the table, but it doesn't seem to make a difference in this case. I have used the application.wait command as a workaround but I'm looking for a better solution. Is there another way to hold off the table refresh until my delete queries have run?</p>
  
  <p>My code is below:</p>
  
  <pre><code>Sub Delete_recipe()
  
  'Set up query
  Dim Recipe_ID As Integer
      Worksheets("Recipe Adder").Calculate
      Recipe_ID = Range("New_recipe_ID").Value
  
  'Open data connection
  Dim Cn As ADODB.Connection
  Set Cn = New ADODB.Connection
  Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Tucker\Desktop\Recipe project\MURPH.xls;Extended Properties=Excel 8.0;" _
  &amp; "Persist Security Info=False"
  
  'Execute delete query
  Cn.Execute "Delete from Recipe_master IN 'C:\Users\Tucker\Desktop\Recipe project\MURPH.accdb' where Recipe_ID =" &amp; Recipe_ID
  Cn.Execute "Delete from Recipe_ingredients IN 'C:\Users\Tucker\Desktop\Recipe project\MURPH.accdb' where Recipe_ID =" &amp; Recipe_ID
  Cn.Execute "Delete from Recipe_instructions IN 'C:\Users\Tucker\Desktop\Recipe project\MURPH.accdb' where Recipe_ID =" &amp; Recipe_ID
  
  'Close connection
  Cn.Close
  Set Cn = Nothing
  
  'Application.Wait (Now + TimeValue("0:00:06"))
  ActiveWorkbook.Connections("Murph Ingredient").Refresh
  
  'Clear data from cells
  Range("New_recipe_name_merged").ClearContents
  Range("Recipe_description").ClearContents
  Range("New_recipe_ingredients").ClearContents
  Range("New_recipe_instructions").ClearContents
  
  End Sub
  </code></pre>
  
  <p>Thanks for your help</p>