[RESOLVED] 'On Error GoTo MockErr1' Not Working
I've made a procedure that creates a directory structure according to a textfile. It works perfectly fine, except there are some files that it can't create (long story).
I've built an error handler to record which files can't be made and then to continue building the rest of the files, but the problem is that when an error occurs the first time, it is recorded fine but the next time an error occurs, VB
pops up a runtime error instead of going to MockErr1.
How can I solve this so that it will always go to MockErr1?
Here's part of the code
VB Code:
Private Sub MakeIt()
On Error GoTo MockErr1 'This is for stubborn filenames
Open App.Path & "\Mock Systems\" & lstTrees.Text & "\" & Trees(i) For Output As #90 'Create the file
Print #90, "Blah"
Close #90
Exit Sub
MockErr:
MsgBox Err.Description
MockErr1:
'Error occured during construction of dir structure
Open App.Path & "\Mock Systems\" & lstTrees.Text & "\Err.txt" For Append As #78
Print #78, "'" & Err.Description & "' {" & Err.Number & "}" & " [" & Trees(i) & "]"
Close #78
Err.Clear
GoTo DoStats
End Sub
Re: 'On Error GoTo MockErr1' Not Working
where this is defined in your procedure...
Re: 'On Error GoTo MockErr1' Not Working
Well actually the code I posted is just an extract from a loop.
DoStats is at the bottom of the loop, here it is:
VB Code:
On Error GoTo MockErr1 'This is for stubborn filenames
Open App.Path & "\Mock Systems\" & lstTrees.Text & "\" & Trees(i) For Output As #90 'Create the file
Close #90
End If
End If
DoStats:
Progress.Value = i
PercentDone = i / UBound(Trees) * 100
lblStatus.Caption = Left$(PercentDone, InStr(1, PercentDone, ".") + 2) & "% Built"
DoEvents
Next i
Exit Sub
MockErr:
MsgBox Err.Description
MockErr1:
'Error occured during construction of dir structure
Open App.Path & "\Mock Systems\" & lstTrees.Text & "\Err.txt" For Append As #78
Print #78, "'" & Err.Description & "' {" & Err.Number & "}" & " [" & Trees(i) & "]"
Close #78
Err.Clear
GoTo DoStats
End Sub
Re: 'On Error GoTo MockErr1' Not Working
May be second run time error occur due to open stmt beingh used in error handler...due to which it is not going to handle it properly but throwing runtime error.
Re: 'On Error GoTo MockErr1' Not Working
Nope. I Changed the 'MockErr1' to Close #90 but I still get the error.
The error I get is 'Path Not Found' and that is the error I want to trap, so there is nothing wrong with my coding, the problem is that it is only trapping the error the first time it occurs, after that it just shows the error instead of going to MockErr1
Re: 'On Error GoTo MockErr1' Not Working
Try changing your code to Resume DoStats instead of GoTo. That should clear the current error condition (no need to do Err.Clear) and jump to DoStats.
Re: 'On Error GoTo MockErr1' Not Working
Pete, you genius, you've done it!
Apparently "You must spread some Reputation around before giving it to pnish again."
But it's the thought that counts ;)
Re: 'On Error GoTo MockErr1' Not Working
Glad to help. Thanks for the thought... :)
Re: 'On Error GoTo MockErr1' Not Working