'Refreshes any query tables in the workbook
Private Function RefreshwbQueryTables(wbReport As Workbook) As ReturnStatus
Dim qt As QueryTable
Dim shtTmp As Variant
Dim SQLTmp As String
On Error GoTo Err_Handler
For Each shtTmp In wbReport.Sheets
If InStr(1, shtTmp.Name, "CHART") = 0 Then
For Each qt In shtTmp.QueryTables
' 'Let's replace any ODBC connections with an OLEDB connection for speed and reliability(?)
' qt.Connection = "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CurrentDb.Name & ";User Id=admin;Password=;"
' qt.MaintainConnection = True
'Rebuild the query table SQL to handle any field changes in the source query/table
' SQLTmp = qt.CommandText
' SQLTmp = "SELECT * " & Right(SQLTmp, Len(SQLTmp) - (InStr(1, SQLTmp, "FROM") - 1))
' qt.CommandText = SQLTmp
' Debug.Print shtTmp.Name
'Refresh the data and wait until everything has been returned
qt.Refresh BackgroundQuery:=False
Next
End If
Next
RefreshwbQueryTables = AllOK
Exit Function
Err_Handler:
RefreshwbQueryTables = FunctionFailed
' MsgBox "Error Here, need to find out what's going on", vbOKOnly, "ERROR! - RefreshwbQueryTables()"
End Function