473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

error handler


Can someone help me? I have an error handler that is not working correct. Below is a snippet, for some reason it read through, all the way to the error handler though there is not one. Thanks.

Public Sub GetData()
On Error GoTo MyHandler

With myObject
msgbox "test"
'- - -- - more code here etc..
End With

MyHandler:
MsgBox "error"

end sub


Nov 22 '05 #1
1 1226
You forgot to exit the Sub if there was no error. Just add an Exit Sub
before the error handling code.

Public Sub GetData()
On Error GoTo MyHandler

With myObject
msgbox "test"
'- - -- - more code here etc..
End With

Exit Sub ' ** add this here **

MyHandler:
MsgBox "error"

end sub

If you're using VB.NET you should *really* consider switching to structured
error handling using try/catch/finally blocks. If you decided to do this
your code would be changed to:

Public Sub GetData()
Try
With myObject
MsgBox "test"
'- - -- - more code here etc..
End With
Catch ex As Exception
MsgBox "Error: " & ex.Message
End Try
End Sub

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada

"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...

Can someone help me? I have an error handler that is not working correct. Below is a snippet, for some reason it read through, all the way to the
error handler though there is not one. Thanks.
Public Sub GetData()
On Error GoTo MyHandler

With myObject
msgbox "test"
'- - -- - more code here etc..
End With

MyHandler:
MsgBox "error"

end sub

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
2
by: Randy Harris | last post by:
I thought that I had a grasp of how VBA error handling functioned, but have just become painfully aware that I don't. I thought that the "On Error GoTo 0" in the second sub below would turn off...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
16
by: Steve Jorgensen | last post by:
I'm trying to figure out if there is a way to generate standard error handlers that "know" if the calling code has an error handler in effect (On Error Goto <label> or On Error Resume Next) before...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
2
by: robert d via AccessMonster.com | last post by:
I have a module with an error handler section. At the top of the module is the following statement: On Error GoTo Err_Ctrl In the error handler is a conditional If statement based on an error...
10
by: robert d via AccessMonster.com | last post by:
I have a global error handler that up until today has been working flawlessly. Let me first provide the relevant code **************************************************************** On Error...
2
by: Jukka Aho | last post by:
When converting Unicode strings to legacy character encodings, it is possible to register a custom error handler that will catch and process all code points that do not have a direct equivalent in...
4
by: jdokos | last post by:
Hello All, I have a procedure that is getting -443 after upgrading to V9.5 FP1. The procedure was written to output only the SQLCODE. Here is the output that is returned: Value of output...
9
by: Daniel Smedegaard Buus | last post by:
Hey all :) I was wondering about the $error_types (I particularly notice the 's' suffix when reading the manual) parameter for 'set_error_handler()': Can be used to mask the triggering of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.