Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Simple Error Handler Q


Hi all,

In my error handler, I would like to include the name of the function itself, and perhaps the line number of the line that caused the error. I have searched the forum and found that there was someone who said that they do this, but there was no code or instructions about how.

Is there a way to get the name of the current function (or sub), and is there a way to get the line number of the error line so that I can put it in my log file? I have an error I need to track down better than I have been...

I know I could set a variable at the start of each function and set it to be the function name manually, and then use that variable in my error handler, but I was hoping for some generic way so that a find & replace could put it in all my log file statements in my error handlers in all my functions quickly.

Thanks in advance.
Swift




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Help With Simple Error Handler
I need some help on getting this error handler to work. In the following code snippet, the array rsSelected sometimes is valid and sometimes it is not (the error generates a 'subscript out of range'). What I want to happen is that if the error occurs then exit the subroutine without the DrawSpatialRecordset running. However, it appears that the error handler doesn't kick in because I repeatedly get the run-time error message and the program bails. Any suggestions are GREATLY appreciated. Thanks.


public Sub DrawSelectedFeatures(byval hDC as StdOle.OLE_HANDLE)
on error GoTo booboohandler

Dim i as Integer

for i = 1 to UBound(rsSelected)
DrawSpatialRecordset rsSelected(i), moPurple, moSolidFill
next

Exit Sub

booboohandler:

End Sub

Declaring An Error Handler Like This... Simple, But Can Someone Help?
I want to declare an error handler like this if possible...

ErrorHandler:

Case err.number whatever
If err.description "whateverdescription" Then
MsgBox "do whateverdescription needs"
Else: MsgBox "a different error message"

Case err.number whateverelse
Msgbox "message for whatever else"

Case err.number yetanother
Msgbox "message for yetanother"

Case else
Msgbox "error handler to catch all other others not accounted for"



Can someone help me write it?

I've been trying it, but i keep either getting errors (like End Select declared in wrong place), or jumping errors and always going to the last one for some reason...


If anyone can please lend some help, please do.

Many thanks.

Simple Error Handler Question
Thanks to all who help others,

I am wondering if anyone can help with me with a question about how to handle the problem of user clicking command button without entering numbers in a textbox. (program closes) here is a sample code:


Code:
Private Sub Command1_Click()


Dim A, B 'to find hypotenuse

A = Text1.Text
B = Text2.Text

Label4.Caption = Sqr((A ^ 2) + (B ^ 2))


End Sub
I found this snippet on the web,
but it displays the msgbox whenever command button is pressed, error or not.


Code:
'In module

Sub ErrHandler()
ErrDesc = err.Description
ErrNum = err.Number
Beep
MsgBox "Error number " & ErrNum & " has occured because: "

& vbCrLf & "Nothing was typed in one or more boxes, (a Zero

will work.)" & vbCrLf & ErrDesc, vbCritical, "Error"

________________________________________

'in form
Private Sub Command1_Click ()
On Error Goto ErrHandle:

'Code here


ErrHandle:
Call ErrHandler

End Sub
Thanks again, if anybody can help
DK

[URGENT] Declaring An Error Handler Like This... Simple, But Can Someone Help?
I want to declare an error handler like this if possible...

ErrorHandler:

Case err.number whatever
If err.description "whateverdescription" Then
MsgBox "do whateverdescription needs"
Else: MsgBox "a different error message"

Case err.number whateverelse
Msgbox "message for whatever else"

Case err.number yetanother
Msgbox "message for yetanother"

Case else
Msgbox "error handler to catch all other others not accounted for"



Can someone help me write it?

I've been trying it, but i keep either getting errors (like End Select declared in wrong place), or jumping errors and always going to the last one for some reason...


If anyone can please lend some help, please do.

Many thanks.

[URGENT] Declaring An Error Handler Like This... Simple, But Can Someone Help?
I want to declare an error handler like this if possible...


ErrorHandler:

Case err.number whatever
If err.description "acertaindescription" Then
MsgBox "do whatever acertaindescription needs"
Else: MsgBox "a different message for the same error number with a different description"

Case err.number whateverelse
Msgbox "message for whatever else"

Case err.number yetanother
Msgbox "message for yetanother"

Case else
Msgbox "error handler to catch all other others not accounted for"



Can someone help me write it?

I've been trying it, but i keep either getting errors (like End Select declared in wrong place), or jumping errors and always going to the last one for some reason...


If anyone can please lend some help, please do.

Many thanks.

Error Handler Inside An Error Handler. Ok To Do?
Is this Ok or am I asking for Trouble.



Code:
Private Sub Do_something()

On error goto FAILURE

Code here........
Exit Sub

FAILURE:
On Error Resume Next

Code to Handle Original Error

End Sub

Error Handler For Database -why Does It Always Go To Error Handler When There Is No Error?
I have setup an error handler on my Form_load of several forms:

It looks like this:
Code:
On Error GoTo Form_load_error

'lines of code

Form_load_error:

Select Case (Err.number) -2147467259
Case 0
If Err.Description = "Unspecified error" Then
MsgBox ("Do something")
End If

Case Else
MsgBox Err.Description
End Select

If Err.Number <> 0 Then
Err.Clear
End If

Exit Sub

End Sub



What I cant understand is that, I had not setup an error handler on my form_load before this...

The form loaded fine and there were no errors.

but now, everytime I try to open the form, I get a blank MsgBox first with only an okay button (and no message obviously). So I commented out the line:
Code:
Case Else
'MsgBox Err.Description <---- commented this line out
End Select


And that stopped the blank MsgBox from being displayed...

BUT!
I can't afford to take this out! What happens if an error other than the one specified occurs? It has to go to the Case Else.

So I NEED that line in there or something like that...

But how do I get it to stop displaying that silly blank MsgBox before every form_load ?


Can anyone understand what is causing it ?


Thanks

Declaring An Error Handler / On Error GoTo In The General Declarations?
Ive been reading in books that somehow you can declare an On Error GoTo ErrorHandlerProcedure in a forms general declarations, and also to declare the actual error handler itself in the general declarations...

But when I tried this it didnt work!

It didnt show an example, but I'm guessing its written the same way as you'd normally write an On Error GoTo and the Error Handler, but maybe I'm wrong?


Can anyone please help by giving me an example of how its done?


Thanks

Declaring An Error Handler / On Error GoTo In The General Declarations?
Ive been reading in books that somehow you can declare an On Error GoTo ErrorHandlerProcedure in a forms general declarations, and also to declare the actual error handler itself in the general declarations...

But when I tried this it didnt work!

It didnt show an example, but I'm guessing its written the same way as you'd normally write an On Error GoTo and the Error Handler, but maybe I'm wrong?


Can anyone please help by giving me an example of how its done?


Thanks

Edit By Shandy: Moved from VB Databases to VB Newbies forum - Please post in forum appropriate to question content



Edited by - Shandy on 4/17/2004 9:18:22 PM

Is It Possible To Setup A Global Error Handler For A Specific Error?
Im wondering is it possible to setup a global error handler?

Quite often my system is coming up with the error:

Error -2147467259 - Unspecified error

which keeps pointing to the database connection db.open line...


and I am wanting to setup an error handler that will handle this error by prompting the user to shutdown the system (with a yes/no).

The only problem is - this error number is generic.... and matches a lot of other errors...

is there any way which I can also say if the string "Unspecified error" also matches - to run my error handler ?


And can someone please tell me how & where I declare this to make it a global error handler? (ie. one that is called no matter where in the program this error is thrown?)

thanks.

Unspecified Error Not Being Handled By VB Application Error Handler
I have a VB 6.0 application running as a service on a Win 2000 server. The VB application has an error routine that writes the error to the event log, then restarts itself. I have noticed over the past several days, that there has been an error thrown by the application, which doesn’t seem to go thru the error handling routine, thus the application doesn’t restart. The error is the ubiquitous ‘Unspecified Error’. The error that appears in the event log is:

The VB Application identified by the event source logged this Application VBEasyLinkInterface: Thread ID: 3148 ,Logged: MsgBox: , Run-time error '-2146949859 (8008251d)':

Unspecified error

Any ideas as to why the application doesn’t seem to be handling the error would be appreciated.


 

Is It Possible To Setup A Global Error Handler For A Specific Error?
Im wondering is it possible to setup a global error handler?

Quite often my system is coming up with the error:

Error -2147467259 - Unspecified error

which keeps pointing to the database connection db.open line...


and I am wanting to setup an error handler that will handle this error by prompting the user to shutdown the system (with a yes/no).

The only problem is - this error number is generic.... and matches a lot of other errors...

is there any way which I can also say if the string "Unspecified error" also matches - to run my error handler ?


And can someone please tell me how & where I declare this to make it a global error handler? (ie. one that is called no matter where in the program this error is thrown?)

thanks.

Handling Error's Inside An Error Handler - How?
Looking for some insight on proper error handling. How would one handle errors that might (for some reason or other) occur within the error handling routine itself, so a program crash can be prevented?

Suppose I have the following Routine;


Code:
Public Function ReadSomeValue(intSomeValue as Integer)

On Error GoTo ErrorHandle1

intSomeValue = intLocationA_Data

Exit Function

ErrorHandle1:
intLocationA_Data = intLocationZ_Data ' Assuming intLocation_Z had corrupt or invalid data for some unknown reason
Resume next

End Function

Capture Runtime Error As Error Handler
Does anyone know how I could go about and do this? I have a program I wrote that inserts stuff into sql, and it gives an error when it hits a duplicate, and I would like to capture that error and save it to a log or something. The error I get is

"run-time error '-2147217873(80040e2f)';"

but I dont know how to deal with them, besides a nice On Error Resume Next

Add An Error Handler
I would like to add an error handler to the code bellow

If the entered data is not a valid date format, msgbox “please reenter the date”, else, msgbox “error” when the error is cause by an invalid date, it should reopen the input box.

Sub InsertDate()

Dim RECORDCOUNT
Dim USERDATE As Date

RECORDCOUNT = Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row

Columns("B:B").Insert SHIFT:=xlToRight

Dim RPOS
RPOS = "B" & RECORDCOUNT
Range(RPOS).Select

USERDATE = InputBox("Enter the desired Transaction Date in MM/DD/YYYY format.", "Transaction Dates")
Range(RPOS).Value = USERDATE

Dim strFILL
RPOS = "B" & RECORDCOUNT - 1
strFILL = "B1:" & RPOS

Range(strFILL).Select
Range(strFILL).Value = USERDATE
End Sub

Can anyone please help me?
I appreciate your help
Thank you
skatz

Bad Error Handler?
Can anyone figure-out why this error handler isn't working?

Code:
Public Sub Try_This()
Dim XlApp As Excel.Application
Dim sql As String
Set MyConn = New ADODB.Connection
MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=T:My_Table.mdb;"
MyConn.Open
Set XlApp = New Excel.Application
sql = "SELECT * FROM Regions"
Set MyRecSet = MyConn.Execute(sql, 0, -1)
Do Until MyRecSet.EOF = True
My_Region = MyRecSet.Fields("Region")
XlApp.Workbooks.Open FileName:="T:" & My_Region & ".xls"
'create PDF (try to find a good "Ne**")
saved_printer = XlApp.ActivePrinter
Ne = -1
NewNe:
Ne = Ne + 1
If Ne >= 100 Then
MsgBox "Problem finding printer.", 64, "Printer Error"
Exit Sub
End If
If Len(Ne) = 1 Then
MyNe = "0" & Ne
Else
MyNe = Ne
End If
On Error GoTo NewNe 'THIS WORKS FIRST TIME THROUGH (on 1st error), BUT NOT AFTER THAT!!!!!!!!!!!!!!!!!!!!!!!!
XlApp.ActivePrinter = "Adobe PDF on Ne" & MyNe & ":"
XlApp.ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"Adobe PDF on Ne" & MyNe & ":", Collate:=True

'close Excel workbook
XlApp.Workbooks("" & My_Region & ".xls").Close
MyRecSet.MoveNext
Loop
XlApp.ActivePrinter = saved_printer 'change printer back
XlApp.Quit

'FREE MEMORY
Set XlApp = Nothing

MsgBox "PDF files created.", 64, "Done!"
End Sub

The ON ERROR piece works only on the first run through (it goes up to the label), but seems to be ignored on the second. It crashes on the line:
Code:
XlApp.ActivePrinter = "Adobe PDF on Ne" & MyNe & ":"
where MyNe = "01" with the error:"Run-time error '1004': Method 'ActivePrinter' of object'_Application' failed."

Error Handler
Hi people. I have a problem.

I have A.exe that uses B.dll.
I have a function at B.dll that uses an error handler.
Like this:

B.dll code

Code:
On Error GoTo Err_BorrarItem
...
Exit Function

Err_BorrarItem:
Err.Raise Err.Number, Err.Source, Err.Description


When an error occurs in B.dll it is raised, it is catched from A.exe and, depending on the error number, it displays a messagebox.
The thing is when i am running from the project group it works ok, it displays the correct message when it is a "known" error.
But when A.exe is running i get the message "invalid procedure call"

Any idea?
Thanks, sorry for my english!

Error Handler
Hi

On my remove record button i have created an error handler.The reason for this is when i press remove record and there are no records to remove i want a box to appearexplainging this.

However the error message i created saying "no recordstoremove still appears even when i remove a record!

this is my code, can anyone tellme whats wrong?

Private Sub cmddelete_Click()

On Error GoTo errorhandler

Adodc1.Recordset.Delete
Adodc1.Recordset.MoveFirst

errorhandler:

MsgBox "No records!", , "Error"


End Sub

thanks

Why Can't One Have An Error Handler Within An Error Handler?
I have read it in the documentation that you can't have an error handler within an error handler. I suppose what is meant is:

sub A()
On Error Goto ErrHandler
'code
exit sub
ErrHandler:
On Error Goto ErrHandler2
'code
Resume

ErrHandler2:
'code
End Sub

Without this what could happen if an error occured in an error handler?

Error Handler
Hi
I am having a problem with error handler. I have an input box which pops up and requests a file name from the a: drive, which will cause error 71 if the disk isn't in the drive. It begins reading the disk and then gives a runtime error , error 5, rather than error 71. If i chnge my Elseif statement to read Elseif = 5, then error 71 is caught by my else statement. First of all why isnt my else staement cathcing error 5, and why doesnt my Elseif statement work.

Hopefully i was clear enough.
Thanks




Code:

filenam = InputBox("Enter a File Name")
Open "a: " For Input As #1

.....


ElseIf Err = 71 Then

resp = MsgBox("Drive door is open make sure it is closed", vbAbortRetryIgnore, , "Error")

If resp = vbIgnore Then
Resume Next
ElseIf resp = vbAbort Then
Exit Sub
ElseIf resp = vbRetry Then
Resume
End If

Else

MsgBox "Error " & Err & " has occured " & Error & vbCrLf & "Please contact the Program Designer"
Exit Sub

Error Handler
how do i return to running code after error 58 has been handled?


Code:
On Error GoTo handleerror
cd_pdf.CancelError = True
cd_pdf.DialogTitle = "Select PDF Drawing File (150Kb or smaller)"
cd_pdf.Filter = "PDF Files |*.pdf"
cd_pdf.ShowOpen
Name cd_pdf.FileName As path_temp & refParentItem.item & ".pdf"
PDF_copy = True
Exit Sub
handleerror:
If Err.Number = 32755 Then
Exit Sub
ElseIf Err.Number = 58 Then
Kill (path_temp & refParentItem.item & ".pdf")
Else
MsgBox "ERROR: " & Err.Number
End If

An Error Handler
I am in a really big need of the good error handler for vabsic run - time error 3021 "no current record"... Please anyone...

Zenag2K

Error Handler
I want a error handle to be wrapped around a submit button that calls another form so if there is a problem in the loading of that form it will rollback and revert back to the error handle from the other form.

I tried putting the error handle in the form load but if the form load errors out and hits the error I cant unload the form I get a error after the load finishes saying form already unloaded.

Thanks

Error Handler
what is a proper way to insert an error handler to a Sub

this code gives error


VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)On Error GoTo dErr If Shift = vbAltMask And KeyCode = vbKeyF4 Then         KeyCode = 0    End If If Shift = vbAltMask And KeyCode = 27 Then        KeyCode = 0End If dErr:MsgBox "An error has occured in " & Me.Name & ".Sub Form_KeyDown" End Sub

Error Handler
VB Code:
cmdPlay.Picture = LoadPicture(App.Path & "play.gif")picPlay.Picture = cmdPlay.PicturepicPause.Picture = LoadPicture(App.Path & "pause.gif") cmdStop.Picture = LoadPicture(App.Path & "stop.gif")cmdOpen.Picture = LoadPicture(App.Path & "open.gif")cmdFF.Picture = LoadPicture(App.Path & "
ext.gif")cmdPre.Picture = LoadPicture(App.Path & "previous.gif")


I have the following image files being loaded into my program, but if one isn't there, I want to be able to display in a msgbox the file that was missing?

Is that possible to find out without to much extra coding?
Thanks inadvance.

Error Handler
Hello,

I have a problem I can't figure out. I have some code that has the following:

While (some condition)

On Error Goto FormatError

date = DateValue(nextDate)
....
....
....

FormatError:

MsgBox "Formatting Error"

Loop

The first time through the loop, if there is an error, then the message box is displayed. However, the second time through if the nextDate value is invalid, then I get a runtime error saying type mismatch! Why does it goto the error handler the first time, but not the second?

Thanks.

Error Handler
Hi All,
In my application i am having chat module.My functionality is whenever a user calls me for a chat it will load a form in my application.When i have opened the commondialog control(Open dialog box) in my application to select a file and the same time if some other user calls me for chat it will try to open a new form and i get the error "Can't display a non-modal form when a modal form is displayed".To overcome this problem i have added a error handler which tracks the error number and says the user to unload the modal window.
My problem is the application doesn't recognize the error handler and it crashes.What should i do to overcome this problem.The error handler i have used is

On Error GoTo Errhand

---Code---

Exit Sub
Errhand:
Select Case Err.Number
Case 401
Msgbox"Close the modal window"
Case Else
Msgbox Err.description
End Select

Error Handler
I am thinking of creating a Error Handler procedure for the nexrt project such that it will trap any error occuring in the whole project.Can any one please advise upon how to do that?

Error Handler
In VBA there is an Add-In that is called "VBA error handler". This puts in great error handler code in your modules... Now.. Is there something like this in VB?? Or Can you make your own?? In that case... What is the first step??

Help On Error Handler
need an example


'** Need to check if report ran okay without errors. If so, keep going. Otherwise,
'** skip this report, create an audit entry, go on to next report.

Error Handler
I need seral examples of error handlers for opening a connection, not being able to query a sql string, connection is down, in case connection is open close..set an error handler.

Basically error handlers for Database, can anyone help?

Error Handler
i have created a macro in a excel workbook and need to include an error handler

the macro transfers data from worksheet "dailyorders" to worksheet named "database" but i need to include a error handler which will produce a message box "database unavailabe" if the worksheet named "database" has undergone a name change

any assistance would be appreciated

Error Handler
Hi can anyone tell me why my error handler programme isnt working???

Code:Option Explicit
Dim cost As Single
Dim Deposit As Single
Dim Discount As Single
Dim Rate As Single
Dim DaysHire As Single



Private Sub ChkDeposit_Click()
If ChkDeposit.Value Then
    LblDep.Caption = "10"

End If
End Sub

Private Sub CmdCalc_Click()

    On Error GoTo ErrorHandler
    If DataValid Then
    cost = Val(txtBikeHire) * Val(txtDaysHire) * Val(LblRate.Caption)
    Deposit = txtBikeHire * 10
    If txtDaysHire > 7 Then
        Discount = cost * 2.5
        lblTotal = (cost - Discount) + Deposit
    End If
    Exit Sub
    
ErrorHandler:
    MsgBox "Invalid Calculate - check your data input"
    
    
End If

End Sub




Private Sub CmdClear_Click()
      Unload frmBikeHire
      frmBikeHire.Show
End Sub

Private Sub CmdExit_Click()
    End
End Sub

Private Sub optCash_Click()
        frmCreditCardDetails.Visible = False
        txtCardType.Visible = False
        txtCardNumber.Visible = False
        txtExpiryDate.Visible = False
End Sub

Private Sub optCheque_Click()
        frmCreditCardDetails.Visible = False
        txtCardType.Visible = False
        txtCardNumber.Visible = False
        txtExpiryDate.Visible = False
End Sub

Private Sub optCreditCard_Click()

        frmCreditCardDetails.Visible = True
        txtCardType.Visible = True
        txtCardNumber.Visible = True
        txtExpiryDate.Visible = True
        
    
End Sub

Private Sub optDecFeb_Click()
    If optDecFeb.Value Then
    Lblcode1.Caption = "C"
    LblRate.Caption = 2.2
    lblSea.Caption = "C"
    
    End If
End Sub



Private Sub optJuneAug_Click()
    If optJuneAug.Value Then
    Lblcode1.Caption = "A"
    lblSea.Caption = "A"
    LblRate = 5
    
    
    End If
    
End Sub

Private Sub optMarchMay_Click()
    If optMarchMay.Value Then
    Lblcode1.Caption = "D"
    LblRate.Caption = 3.6
    lblSea.Caption = "D"
    End If
End Sub

Private Sub optSeptNov_Click()
    If optSeptNov.Value Then
    Lblcode1.Caption = "B"
    LblRate.Caption = 2.75
    lblSea.Caption = "B"
    End If
    
End Sub

Private Sub txtBikeHire_Change()
LblBicycleHire.Caption = txtBikeHire
End Sub

Private Sub txtDaysHire_Change()

LblDaysHire.Caption = txtDaysHire

If Val(txtDaysHire.Text) >= 7 Then
LblDisc.Caption = "2.5"

Else

If Val(txtDaysHire.Text) < 7 Then
LblDisc.Visible = False
End If


End If

End Sub
                                    
                                    
Public Function DataValid() As Boolean


MsgBox "Invalid Calculate - Check Your Data Input"

DataValid = False
If TxtName = "" Then
    MsgBox "Please enter your Name"
TxtName.SetFocus
Exit Function
End If

If Not IsAddress(txtAddress.Text) Then
    txtDate.SetFocus
    MsgBox "Please Your Address"
Exit Function
End If

If Not IsBicycleHire(txtBicycleHire.Text) Then
    txtDate.SetFocus
    MsgBox "Please select Amount Of Bicycles"
Exit Function
End If

If Not IsDaysHire(txtDaysHire.Text) Then
    txtDate.SetFocus
    MsgBox "Please Select amount of days"
Exit Function
End If

DataValid = True

End Function

VBA IDE Error Handler
Is it possible to programatically set the error handler? I want to be able to turn down the error handler when a given program executes.



Dave

ERROR HANDLER
Dear Everyone.

Thanks everyone who replied me about Crystal reports. Now I have another question.

Is it possible to send back an error msg generated in a called procedure from the interface?

example

From the interface i call a method on the domain, and it calls another method which has an error handler, but i need to go back to the interface to display a msg to the user indicating that there was an error.

is it like Java, or the error msg is just for the class which has the error handler?


Thanks a lot

W





Edited by - BlueMonday on 7/24/2002 6:42:36 PM

Error Handler
I have an error handler that I use extensively. However most of the times I just want to be able to inform the user of the error and then move on. Sometime I save info on errors too. However they way that my error handler works now is that it terminates the program when an error is being detected. Please help me modify it so that it “tolerates” mistakes and just warns the user of the error.

My code is:

Public Sub mainProgram()
…..
On Error GoTo Handler
Exit Sub

Handler:

Select Case Err.Number
Case 600
Msgbox(“Error type 102”)
Case 601
Msgbox(“fatal error!)
………
Case Else
End Select
End Sub

And in a sub somewhere in the code e.g. :
If x > 10 then
Msgbox(“Wrong!”)
Err.raise 601
End if

As you can see if error occurs the error handler is called and when the code for current error is finished the macro ends. Instead I want to call the handler, do whatever it is I want to do for a certain error but then continue in the sub where I left with the error. Please help me out! Thank you very much in advance!

Error Handler
Hi All,

I have a piece of code where I am loading images into a picture box.

Now, if the path is not available it is throwing Run time error '76' Path not found]

I have added error handler....but control is not moving into handler.

Private Sub Form_Load()
Dim count As Integer
On Error GoTo ErrorHandler
----

--------

ErrorHandler :

MsgBox "The following error was raised in MySub:" & vbCrLf & vbCrLf & _
Err.Number & ": " & Err.Description

End sub


Can anybody tell me the reason ?
Is there any other things I have to set ?

Looking forward for your guidance.

Regds,
Sam

Error Handler
Hi everyone ... I should be able to figure this out, but I keep coding myself in circles
I have dozens of textboxes that I convert to Currency in a seperate module.
The problem is that not all these are mandatory inputs, so the Convert function ends up with a TypeMisMatch error '13', because it is being passed an empty string "".
What I would like to do is within this module change any empty string to 0.
Due to validation routines and other controls being visible if certain textboxes <> "", I cannot just set the text property to 0.
I can capture the error, but cannot figure out an elegant way to change the emptystring to 0, and i KNOW its going to end up very simple!!

Thanks in advance
Michael

Error Handler
In a huge application in most procedures and functions the error handling is done this way:

private MyProc()
on error GoTo Err_Handler
'.............
'..............
'Body of procedure or function
Exit Sub
Err_Handler:
ErrObject.OneOfMethods(Parameter)
End Sub



ErrObject is an object with many methods. ErrObject itself very often is a source for error, because either ErrObject was not created by some reason, or something wrong with parameters and so on.
Any idea, how to make Error Handling better?
Thank you.
Vlad

Error Handler
hi there im looking for an error nadler to be added to some code that will only accept numbers in a text box

so if a letter is inputed then the error handler put up a msgbox saying

If errorhandler is " " ' a letter unstead of a number
MsgBox " you have not entered a valid number please try again", vbCritical, "Error!"


or something like that

Printer Error Handler
Hi,
I have a function that prints a RTF, I have added an error handler to it and now get an unknown error. Is this because I have put an error handler within the Function, or should this work.

How Do I Get Vb Procedure Name For Error Handler
i am trying to make an error handle for my software

the code structure i given below

private sub sb_getnames()
on error go to err_trap
bla bla bla
exit sub
err_trap:
msgbox err.description & " sb_getnames"
end sub

is there a way that i can get the procedure name some how so that i can use it in message box instead of writting manually the name of the procedure thanks in advance.

On Error Event Handler
I am trying to create an "on error" event, but it does not work, no matter what I do, it just returns runtime error 509. I have searched the forum and tried all the solutions, but it just doesnt seem to goto ADError. PLEASE HELP !!!

Code:
Sub AcceptDelete()

WordBasic.AcceptAllChangesInDoc
WordBasic.DeleteAllCommentsInDoc
ActiveDocument.Save

On Error GoTo ADError

ADExit Sub

Error:

Message = MsgBox("No comments to delete", vbInformation, "No Comments...")

End Sub

Error Handler Only Works Once
Hi,

I have a little program that backs up a file to another location. If the file is open, it's supposed to wait and try again. Unfortunately, my error handler only seems to work once, then on the second try in copying the file VB6 comes up with a dialog box with Error 70, Permission Denied. I've Added 3 different statements trying to disable the error handler then re-enable it, but I still get the same result. It almost seems like Visual Basic is automatically trying to avoid a loop condition.

I have a VB resource online that I've searched, plus MSDN, and haven't found any other reference for my situation. I wonder if I totally need to rewrite my code and call the filecopy as a function or something, but I'm not too sure on how to do that. I'm hoping someone has the answer to this problem.



Code:
Private Sub Form_Load()
Dim strDestination As String
Dim strDate As String
Dim PauseTime, Start
strDate = Format$(Date, "mm-dd-yy")
strDestination = "S:AdministrativeMACBackupMACLOG2004 Backup " & strDate & ".xls"
RetryCopy:
On Error GoTo CopyError
If Dir(strDestination) = "" Then _
FileCopy "S:AdministrativeMACMACLOG2004.xls", strDestination
SetAttr strDestination, vbReadOnly
End
CopyError:
'delay and retry the copy
PauseTime = 5
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
On Error GoTo 0
Err.Clear
GoTo RetryCopy
' Resume still generates Permission Denied on 2nd try
End Sub

Global Error Handler
does anybody know how to find out when an error occurred so instead of displaying a msgbox with the error and then exiting the program i could just exit the function/sub/...

Error Handler Problem
hihi my vb friends.
im making a very basic calculator, and all has been going fine. Then i decided i wanted the screen to display "MATH ERROR" if the person did a division by zero. i decided to sum up all errors with the same display. this is the code i used.

...think this is how u get it to display in vb form...

Code:
Private Sub Equals_Click()
If Screen <> "MATH ERROR" Then
Part2 = Screen
On Error GoTo Errhandler
If Equation = "+" Then
Screen = Val(Part1) + Val(Part2)
ElseIf Equation = "-" Then
Screen = Val(Part1) - Val(Part2)
ElseIf Equation = "/" Then
Screen = Val(Part1) / Val(Part2)
ElseIf Equation = "*" Then
Screen = Val(Part1) * Val(Part2)
End If
Errhandler:
MsgBox ("bing")
Else
calculator.SetFocus
End If
End Sub

This has been changed slightly so it brings up a mesage box, instead of error, just to illistrate the problem. The code brings up the msgbox if an error occurs, but it also brings up the msgbox, no matter what calculation i do. I have tried moving the errhandler around to different places, but it keeps coming up. why? Is this some really obvious mistake?

Thanks in advance!!

Error Handler Problem
Hi,

In my following code, in the "ErrHandler" routine, when I unload the form, then also it is running procedures called after "ON ERROR" statement.

How to get rid of this? I want to unload the form after the message box.


-----------------------------------------------------
Private Sub Form_Load()
On Error GoTo Errhandler

Call AdjustGrid
'Progress bar adjustment
Call showpercent

'Show Balance AMount
Call BalanceAmount

Call TextBoxAdjust

Errhandler:
Select Case Err.Number
Case 11
MsgBox "No Amount Present. Goto MONETARY DETAILS to enter New Budget.", vbCritical, "ERROR"
Unload Me
End Select
End Sub

---------------------------------------------------------------

ComboBox Error Handler
We all know that a dropdown list Combobox ( Style 2 ) cannot set its Text property to a value that is not already containded in its list. Example : If I try to set Combo1.Text = "WhoCares" and that "WhoCares" is not in the Combo1 List, it will generate an error. Is there a way to avoid this error, even by adding the "WhoCares" value to the list before the error occurs?
Thanx

How Can I Use An Error Handler With The Webrowser
VB 5.0. learning edition.
Hi,
I use error handlers in my App. When I use the webrowser control to open a file (*.html or *.ppt) on the cd-rom, if the the cd is not in the drive, I have only the message "Navigation cancelled" without more error. Such behaviour is not trap by the error handler:
On error goto "errhandler"
WebBrowser1.Navigate MyCD & ":/pres/mystere.html"
How can i trap such an error (file not found on the cd-rom with the webrowser).
Thanks,
Regards,
Wil

Copyright © 2005-08 www.BigResource.com, All rights reserved