Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Error Handler Not working 2nd time

Hey guys, below is an error handler I have. It will goto
label ErrHandler2a when there is an error. The error I am
trying to trap is error 52, so below that label I specify
what to do when it encounters error type 52. The reason
there would be an error (error type 52) is if one of the
variables are an invalid file path. This code works the
first time it encounters the error, however the 2nd time
it encounters, it displays the debug message telling me
error type 52. This is the exact thing it handled the
first time, whats wrong with it the 2nd time? I always
thought that when the "next" statement executes, the error
is reset. Is this right?

On Error goto ErrHandler2a
ABFileFrom2 = BS & "\" & f1x.Name
ABFileTo2 = ABL2 & "\" & f1x.Name
FileCopy ABFileFrom2, ABFileTo2
DoEvents
ErrHandler2a:
If Err.Number = 52 Then
Else
End If
Else
Resume Next
End If
Next
End If
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Error Handler Not working 2nd time

I can't exactly follow your code, but it looks like your Resume Next (not
Next) is within an if structure that doesn't get executed. Try:

Sub test()
On Error GoTo ErrHandler2a
'Do strange and unusual things
Exit Sub
ErrHandler2a
If Err.Number = 52 Then
'Handle error 52
Else
MsgBox Err.Number & vbCRLF & Err.Description
End If
Resume Next
End Sub

-----Original Message-----
Hey guys, below is an error handler I have. It will goto
label ErrHandler2a when there is an error. The error I am
trying to trap is error 52, so below that label I specify
what to do when it encounters error type 52. The reason
there would be an error (error type 52) is if one of the
variables are an invalid file path. This code works the
first time it encounters the error, however the 2nd time
it encounters, it displays the debug message telling me
error type 52. This is the exact thing it handled the
first time, whats wrong with it the 2nd time? I always
thought that when the "next" statement executes, the error
is reset. Is this right?

On Error goto ErrHandler2a
ABFileFrom2 = BS & "\" & f1x.Name
ABFileTo2 = ABL2 & "\" & f1x.Name
FileCopy ABFileFrom2, ABFileTo2
DoEvents
ErrHandler2a:
If Err.Number = 52 Then
Else
End If
Else
Resume Next
End If
Next
End If
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Error Handler Not working 2nd time

Todd,

You need to use a Resume statement in your error handling block in
order to "reset" the error handler. Otherwise, you are still in
"error mode" and cannot trap subsequent errors.

Look in VBE help for 'Resume Statement' and 'Error Handling'.

If Err.Number = 52 Then
' Handle error.
Resume 'one of its forms from VBE Help.
End If

HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------

Hey guys, below is an error handler I have. It will goto
label ErrHandler2a when there is an error. The error I am
trying to trap is error 52, so below that label I specify
what to do when it encounters error type 52. The reason
there would be an error (error type 52) is if one of the
variables are an invalid file path. This code works the
first time it encounters the error, however the 2nd time
it encounters, it displays the debug message telling me
error type 52. This is the exact thing it handled the
first time, whats wrong with it the 2nd time? I always
thought that when the "next" statement executes, the error
is reset. Is this right?

On Error goto ErrHandler2a
ABFileFrom2 = BS & "\" & f1x.Name
ABFileTo2 = ABL2 & "\" & f1x.Name
FileCopy ABFileFrom2, ABFileTo2
DoEvents
ErrHandler2a:
If Err.Number = 52 Then
Else
End If
Else
Resume Next
End If
Next
End If


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 260
Default Error Handler Not working 2nd time

thanks guys. I used resume Next and that worked. I
wanted to use the goto method because then I could specify
the exact error.


-----Original Message-----
Todd,

You need to use a Resume statement in your error handling

block in
order to "reset" the error handler. Otherwise, you are

still in
"error mode" and cannot trap subsequent errors.

Look in VBE help for 'Resume Statement' and 'Error

Handling'.

If Err.Number = 52 Then
' Handle error.
Resume 'one of its forms from VBE Help.
End If

HTH
Paul
----------------------------------------------------------

----------------------------------------------------
Be advised to back up your WorkBook before attempting to

make changes.
----------------------------------------------------------

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

Hey guys, below is an error handler I have. It will

goto
label ErrHandler2a when there is an error. The error I

am
trying to trap is error 52, so below that label I

specify
what to do when it encounters error type 52. The reason
there would be an error (error type 52) is if one of the
variables are an invalid file path. This code works the
first time it encounters the error, however the 2nd time
it encounters, it displays the debug message telling me
error type 52. This is the exact thing it handled the
first time, whats wrong with it the 2nd time? I always
thought that when the "next" statement executes, the

error
is reset. Is this right?

On Error goto ErrHandler2a
ABFileFrom2 = BS & "\" & f1x.Name
ABFileTo2 = ABL2 & "\" & f1x.Name
FileCopy ABFileFrom2, ABFileTo2
DoEvents
ErrHandler2a:
If Err.Number = 52 Then
Else
End If
Else
Resume Next
End If
Next
End If


.

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
Error handler linto Excel Discussion (Misc queries) 1 February 11th 10 12:17 PM
Error Handler sharad Excel Discussion (Misc queries) 1 September 17th 07 06:38 PM
Error Handler Not Working Bill Excel Discussion (Misc queries) 0 August 25th 05 07:13 PM
Compile-time Error Handler Mark Repsher Excel Programming 1 February 9th 04 07:08 PM
error handler Fleur Excel Programming 1 November 20th 03 06:06 AM


All times are GMT +1. The time now is 03:52 PM.

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"