1

I've created a button with VBA which has the function to refresh two queries when you click on it.

MsgBox "please be patient, this operation may take several minutes."
ThisWorkbook.Connections("Query - Load").Refresh
ThisWorkbook.Connections("Query - Start").Refresh
MsgBox "opperation successfully completed "

But I don't know how to wait until the first query is over and then launch the second one. Currently both queries are refreshed at the same time and as you can imagine the second query uses the data created by the first one.

I was thinking of creating 2 buttons for each query but I also don't know how to indicate when the first operation ends.

thanks for your help

Xodarap
  • 343
  • 1
  • 6
  • 23
  • https://stackoverflow.com/questions/8925403/excel-vba-refresh-wait and https://learn.microsoft.com/en-us/office/vba/api/excel.odbcconnection.backgroundquery – DS_London Dec 16 '20 at 15:39

1 Answers1

0

Do the following:

MsgBox "please be patient, this operation may take several minutes."
ThisWorkbook.Connections("Query - Load").Refresh
Do Until Application.CalculationState = xlDone
    If Application.CalculationState = xlDone then
        ThisWorkbook.Connections("Query - Start").Refresh
        MsgBox "opperation successfully completed."
    End If
Loop
Toni
  • 1,555
  • 4
  • 15
  • 23