473,395 Members | 1,539 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,395 software developers and data experts.

Re-use values of err.number and err.description after a msgbox in the error handler

What I'm trying to do is to re-use the values of err.number and
err.description after displaying them in a MsgBox. The values seem to
auto clear and not be re-usable on a second reference.

For example - if I construct this:

Function ThisFunctionGeneratesAnError()
On Error GoTo ErrorHandler

'code that generates an error

ExitErrorHandler:
Exit Function
ErrorHandler:
msgox err.number & " - " & err.description
call SomeOtherFunction(err.number, err.description)
Resume ExitErrorHandler
End Function

What happens is the message box displays correctly with:
"1234 - Error message text"
but the function SomeOtherFunction is passed the values:
SomeOtherFunction(0,"")

If I reverse the order of the code to:

call SomeOtherFunction(err.number, err.description)
msgox err.number & " - " & err.description

What happens is the function SomeOtherFunction is passed the values
correctly:
SomeOtherFunction(1234,"Error message text")
but the message box appears as:
"0"

Is there a way to avoid this behaviour, without having to construct a
mess that looks like:

....
ErrorHandler:
Dim myErrNumber as long, myErrorText as String
myErrNumber=err.number
myErrorText=err.description
msgox myErrNumber & " - " & myErrorText
call SomeOtherFunction(myErrNumber, myErrorText)
Resume ExitErrorHandler
End Function

Thanks,
lq

Nov 13 '05 #1
1 3509
Many kinds for VBA statement clear the Err object. The answer is pretty
simple, though - copy the values to variables immediately, then use the
variables.

Personally, I like to create a function called something like ErrCapture that
takes the Err object as a parameter, copies the Err properties to properties
of a class instance, and returns the instance. The class becomes a good
central location to put code for presenting error dialogs, writing errors to
log tables, etc.

On 5 Feb 2005 03:51:49 -0800, "laurenq uantrell" <la*************@hotmail.com>
wrote:
What I'm trying to do is to re-use the values of err.number and
err.description after displaying them in a MsgBox. The values seem to
auto clear and not be re-usable on a second reference.

For example - if I construct this:

Function ThisFunctionGeneratesAnError()
On Error GoTo ErrorHandler

'code that generates an error

ExitErrorHandler:
Exit Function
ErrorHandler:
msgox err.number & " - " & err.description
call SomeOtherFunction(err.number, err.description)
Resume ExitErrorHandler
End Function

What happens is the message box displays correctly with:
"1234 - Error message text"
but the function SomeOtherFunction is passed the values:
SomeOtherFunction(0,"")

If I reverse the order of the code to:

call SomeOtherFunction(err.number, err.description)
msgox err.number & " - " & err.description

What happens is the function SomeOtherFunction is passed the values
correctly:
SomeOtherFunction(1234,"Error message text")
but the message box appears as:
"0"

Is there a way to avoid this behaviour, without having to construct a
mess that looks like:

...
ErrorHandler:
Dim myErrNumber as long, myErrorText as String
myErrNumber=err.number
myErrorText=err.description
msgox myErrNumber & " - " & myErrorText
call SomeOtherFunction(myErrNumber, myErrorText)
Resume ExitErrorHandler
End Function

Thanks,
lq


Nov 13 '05 #2

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

Similar topics

4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
10
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
2
by: sky2070 | last post by:
i have two file with jobapp.html calling jobapp_action.php <HTML> <!-- jobapp.html --> <BODY> <H1>Phop's Bicycles Job Application</H1> <P>Are you looking for an exciting career in the world of...
5
by: Jamie Wright | last post by:
I have a problem with an HTML form. I have a form which I want to be able to type basic HTML code into it. When the submit button is selected the data is then previewed and added back into the text...
1
by: Brian | last post by:
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
2
by: JW | last post by:
I wanted have this as part of a flood control script: <? echo ("Flood control in place - please wait " . $floodinterval . " seconds between postings."); sleep(5); // go back two pages echo...
2
by: Frans Schmidt | last post by:
I want to make a new database with several tables, so I did the following: <?php CREATE DATABASE bedrijf; CREATE TABLE werknemers (voornaam varchar(15), achternaam varchar(20), leeftijd...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.