Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Capturing query table errors

How do I intercept query table errors, bypassing the Excel ones?

Here's an example of what I'm trying to do using examples from the Help
files:
Sub Macro2()
Workbooks(1).Activate
Application.DisplayAlerts = False ' This doesn't make a difference for my
purposes
On Error GoTo ErrorHandler
Selection.QueryTable.Refresh BackgroundQuery:=False
GoTo Exit_Sub

ErrorHandler:
Msg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source &
Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext

Exit_Sub:
On Error Resume Next
Application.DisplayAlerts = True
End Sub

For testing I've moved the database to a different folder so the first error
window is "Please Enter MS JET OLE DB Initialization Information", then my
example message box. I want to COMPLETELY bypass the Windows error window
and just use mine.

Suggestions?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Capturing query table errors

I think you're already achieving this.
To get the ODBC QueryTable error:
For i = 1 To Application.ODBCErrors.Count
msg = msg & Application.ODBCErrors(1).ErrorString
Next

There is the equivalent for OLEDB QueryTables: Application.OLEDBErrors

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"T. Erkson" wrote in message
...
How do I intercept query table errors, bypassing the Excel ones?

Here's an example of what I'm trying to do using examples from the Help
files:
Sub Macro2()
Workbooks(1).Activate
Application.DisplayAlerts = False ' This doesn't make a difference for
my
purposes
On Error GoTo ErrorHandler
Selection.QueryTable.Refresh BackgroundQuery:=False
GoTo Exit_Sub

ErrorHandler:
Msg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source &
Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext

Exit_Sub:
On Error Resume Next
Application.DisplayAlerts = True
End Sub

For testing I've moved the database to a different folder so the first
error
window is "Please Enter MS JET OLE DB Initialization Information", then my
example message box. I want to COMPLETELY bypass the Windows error window
and just use mine.

Suggestions?





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Capturing query table errors

Thanks Rob. Taking your example I added to my tester and got this which
helps some but still does not bypass the Windows error window :-( For the
query table it is the OLEDB error message that gets tagged, not the ODBC.

Sub Macro2()
'
' Macro2 Macro
'
Workbooks(1).Activate
Application.DisplayAlerts = False
On Error GoTo ErrorHandler

Selection.QueryTable.Refresh BackgroundQuery:=False
GoTo Exit_Sub

ErrorHandler:

msg = "Module Error #=" & Str(Err.Number) & " was generated by " &
Err.Source & Chr(13) & _
"Module Error Description=" & Err.Description & Chr(13)

'ODBC
For i = 1 To Application.ODBCErrors.Count
msg = msg & "ODBC ERROR=" & Application.ODBCErrors(1).ErrorString &
Chr(13)
Next

'OLEDB
For i = 1 To Application.OLEDBErrors.Count
msg = msg & "OLEDB ERROR=" & Application.OLEDBErrors.Item(1).ErrorString
& Chr(13) & _
"OLEDB SQL STATE=" & Application.OLEDBErrors.Item(1).SqlState &
Chr(13)
Next

MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext

Exit_Sub:
On Error Resume Next
Application.DisplayAlerts = True
End Sub

"Rob van Gelder" wrote in message
...
I think you're already achieving this.
To get the ODBC QueryTable error:
For i = 1 To Application.ODBCErrors.Count
msg = msg & Application.ODBCErrors(1).ErrorString
Next

There is the equivalent for OLEDB QueryTables: Application.OLEDBErrors

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"T. Erkson" wrote in message
...
How do I intercept query table errors, bypassing the Excel ones?

Here's an example of what I'm trying to do using examples from the Help
files:
Sub Macro2()
Workbooks(1).Activate
Application.DisplayAlerts = False ' This doesn't make a difference for
my
purposes
On Error GoTo ErrorHandler
Selection.QueryTable.Refresh BackgroundQuery:=False
GoTo Exit_Sub

ErrorHandler:
Msg = "Error # " & Str(Err.Number) & " was generated by " & Err.Source

&
Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext

Exit_Sub:
On Error Resume Next
Application.DisplayAlerts = True
End Sub

For testing I've moved the database to a different folder so the first
error
window is "Please Enter MS JET OLE DB Initialization Information", then

my
example message box. I want to COMPLETELY bypass the Windows error

window
and just use mine.

Suggestions?







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Capturing query table errors

Whoa. Instead of running the macro by using the Run Macro button I assigned
the code to a CommandButton and it DID bypass the Windows error window.
Damn, learn something new with Excel every day :-)

Toby


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Query to Access table errors "do not have necessary permissions Al Excel Discussion (Misc queries) 0 February 8th 08 03:51 AM
External Web Query Errors tokyo4tokyo Excel Worksheet Functions 0 June 25th 06 04:14 AM
Web query errors??? Ryan Jones Excel Discussion (Misc queries) 1 March 13th 06 09:19 PM
Web Query - Submitting Data and Capturing Result Ben Excel Discussion (Misc queries) 0 October 6th 05 02:29 PM
Capturing query table errors T. Erkson Excel Worksheet Functions 1 February 24th 05 09:26 PM


All times are GMT +1. The time now is 04:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"