PDA

View Full Version : Cancel querytable.refresh



pulsar777
08-02-2018, 10:05 AM
Hi,
my querytable refreshes its data from external source and then rest of the code is executed:



.ListObjects(1).QueryTable.Refresh BackgroundQuery:=False
' ... rest of the code


This way the rest of code waits until refresh is finished.
However I'd like to be able to cancel the refresh.

I tried with
BackgroundQuery:=True , this gave me option in statusbar to cancel it but rest of the code is run immediately without waiting.
Following:

Application.CalculateUntilAsyncQueriesDone let the rest of code wait but then I loose the option in statusbar to cancel.
Also I tried to launch a modeless form with button which onClick would execute
.ListObjects(1).QueryTable.CancelRefresh , but the form shows without button and inactive.

Can someone please advise ?

pulsar777
08-06-2018, 08:55 AM
Still no tips ? Anything not clear about question ?

Aflatoon
08-07-2018, 03:30 AM
You'd need to use a class module to hook into the events of the querytable, and then call the rest of the code from the AfterRefresh event, assuming it was successful. I answered a similar question here, which has sample code: https://stackoverflow.com/questions/26983053/how-to-call-macro-after-refresh-or-refresh-all-button-pressed