|
-
Apr 22nd, 2006, 02:26 AM
#1
Thread Starter
Fanatic Member
[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
-
Apr 22nd, 2006, 02:30 AM
#2
Re: 'On Error GoTo MockErr1' Not Working
where this is defined in your procedure...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Apr 22nd, 2006, 02:35 AM
#3
Thread Starter
Fanatic Member
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
-
Apr 22nd, 2006, 02:49 AM
#4
Hyperactive Member
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.
-
Apr 22nd, 2006, 03:17 AM
#5
Thread Starter
Fanatic Member
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
-
Apr 22nd, 2006, 03:27 AM
#6
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.
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Apr 22nd, 2006, 03:34 AM
#7
Thread Starter
Fanatic Member
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
-
Apr 22nd, 2006, 03:37 AM
#8
Re: 'On Error GoTo MockErr1' Not Working
Glad to help. Thanks for the thought...
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Apr 22nd, 2006, 03:42 AM
#9
Thread Starter
Fanatic Member
Re: 'On Error GoTo MockErr1' Not Working
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|