Error Handling and For-Next Loops

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I am in the (hopefully) last stage of finishing my File Scanner. However, I have run into some files where the Permission is denied (Err.Number=70). To get around this, I have set up an Error Handler. The main snippets of my program is shown below

-----------------------------
Sub StoreFiles(

On Error Goto ErrHandle

..

For Each File in File

..

SkipFile

Next Fil

..

Exit Su

ErrHandler

If Err.Number=70 The

Resume SkipFil

EndI

End Sub(
-----------------------------

However, doing this comes back with the error that the For Loop wasn’t initialised (Error 92)â€

How can I get around this

Many thanks for your help

SuperJas
 
Use inline error handling: Wrap the call that raises the error in On Error
Resume Next and On Error Goto 0,

On Error Resume Next
<line(s) that raise(s) error>
On Error Goto 0

which just ignores the error regardless, or use something like this, which
re-raises unexpected errors, but ignores expected ones.

On Error Resume Next
<line that raises error>
ErrNum = Err.Number
If ErrNum <> 0 Then
If ErrNum <> 70 Then
Err.Raise ErrNum 'or Exit Sub, or,...
End If
End If

Bob

SuperJas said:
Hi,

I am in the (hopefully) last stage of finishing my File Scanner. However,
I have run into some files where the Permission is denied (Err.Number=70).
To get around this, I have set up an Error Handler. The main snippets of my
program is shown below:
 
Back
Top