Error handler Not working a 2nd time

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

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

Hey guys above is my code (Error Handler). If it trys to
copy a file from or to an invalid file path I get an error
(Error type 52) so I set up an error to trap it. It works
on the first error but then when it gets here and there is
a 2nd error I get the debug screen that says error 52 -
the exact thing my error handler handled correctly the
first time. And I thought once it hit the next statment,
the error was cleared.

What do I do?

Thank you
Todd Huttenstine
 
I think you chopped too much out of your posted code. I got compile errors with
your existing code.

But this worked ok for me:

Option Explicit
Sub testme01()

Dim ABFileFrom2 As String
Dim ABFileTo2 As String
Dim BS As String
Dim ABL2 As String

BS = "C:\my documents\ecel"
ABL2 = "C:\my documents\excel\test"

On Error GoTo ErrHandler2a
ABFileFrom2 = BS & "\" & "test1.txt" ' f1x.name
ABFileTo2 = ABL2 & "\" & "test1.txt" ' f1x.Name
FileCopy ABFileFrom2, ABFileTo2
DoEvents

'don't want to run errHandler2A again...
Exit Sub
ErrHandler2a:
MsgBox Err.Description
Err.Clear 'resume next clears it, too
Resume Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top