How to confirm Successful refresh

Gavona

New member
Joined
Sep 10, 2018
Messages
4
Reaction score
0
Points
0
Excel Version(s)
10
We are using PowerQuery as Excel 2010 Add-In. We are new to this but I am creating processes that other less expert users use.

I have a query that merges and compares multiple files leading to the updating of two excel tables.
I then have a pivot table that is based on one of these tables.
Where they are not fixed, I use parameters stored in the workbook to hold the filenames and paths that are the source of the queries.

To ensure that the pivots update after the table has refreshed I use a macro:
Code:
    With ThisWorkbook        .RefreshAll
        Application.CalculateUntilAsyncQueriesDone
        For Each pc In .PivotCaches
            pc.Refresh
        Next pc
    End With
    ans = MsgBox("Queries have been refreshed and then pivot tables")

All works as intended UNTIL..... One of the filepath parameters was entered incorrectly. The query then failed to refresh but the user still got the message suggesting that the operation had completed. The Tables did not update or return no data or anything that would be easy to spot through normal checks. The best I can do at present is to tell them to have the Query Pane Open and look out for "Download did not complete" or other errors. What I would prefer via PowerQuery or VBA is to be able to provide a clear message about whether the refresh was successful (and ideally what went wrong). Can anyone help please?
 
Hi Gavona,

So of the top of my head, I don't know a way to test if a query actually worked or not.

What you might want to try is setting up a test that checks if your intended query errors or not inside PQ, and then return a "Success", "Failed" to a table. You could then test the results of that table cell and make your VBA react accordingly.

Chris Webb has a writeup on how to handle errors here: https://blog.crossjoin.co.uk/2014/09/18/handling-data-source-errors-in-power-query/

Hope that helps!
 
That link looks very helpful Ken, thanks. Apologies if I don't post further soon to let you know how I get on - I am on holiday for next 10 days.
 
Back
Top