GoatieEddie
Technical User
Unexpected behaviour going on here! I have the following macro that updates queries linked to an Access table and then saves the file using a distinct filename. However, even though I am using the BackgroundQuery = false, I am getting a prompt box saying the action (ie the saveas) will cancel a pending refresh and as such the sheet doesn't update before it saves. I have checkd the syntax adn everything and can't see what is wrong. Any clues?
many thanks,
GE
Code:
Sub change_queries(New_Entity)
Old_Entity = ActiveWorkbook.Worksheets("Summary Sheet").Range("a1")
For Each ws In ActiveWorkbook.Worksheets
For Each qt In ws.QueryTables
current_sql = qt.CommandText
new_sql = Replace(current_sql, Old_Entity, New_Entity)
qt.CommandText = new_sql
qt.Refresh BackgroundQuery = False
Next qt
Next ws
ActiveWorkbook.Worksheets("Summary Sheet").Range("a1") = New_Entity
ActiveWorkbook.SaveAs "W:\Returns_" & New_Entity & "_" & Format(Date, "ddmmyy")
End Sub
many thanks,
GE