View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default problem with "Refresh BackgroundQuery=False"

The problem may be nothing to do with Excel (hence the generic 1004 error),
but one of the data access layers used to retrive the data. There are 2
error collections associated with data accesss that may be populated
depending on provider etc. See if you get anything useful.

Private Sub CommandButton2_Click()

On Error GoTo Handler

'Change to the name/location of your querytable
ActiveSheet.QueryTables("QT1").Refresh BackgroundQuery:=False

Exit Sub

Handler:
Dim Msg As String
Dim i As Long

Select Case Err.Number
Case 1004
With Application.ODBCErrors
Msg = "ODBC Errors :" & vbNewLine
For i = 1 To .Count
Msg = Msg & .Item(i).ErrorString & vbNewLine
Next
End With

With Application.OLEDBErrors
Msg = Msg & "OLEDB Errors :" & vbNewLine
For i = 1 To .Count
'More info available on OLEDB error if required
Msg = Msg & .Item(i).ErrorString & vbNewLine
Next
End With

Case Else
Msg = "Error Number: " & Err.Number & vbNewLine & Err.Description
End Select

MsgBox Msg

End Sub



"Johnson" wrote in message
...
Hi,
I just want to know if there's error ending up at the code "Refresh
BackgroundQuery=False" and given the error message e.g. error code 1004.
My question's are;
1. What's the reason behined
2. How to fix it.

--
Johnosn