Error handling with a handling routine

B

ben

I have a sub that attempts to read from a file,
if the file does not exist i then procedd to a handling routine to try to
copy the back up, the problem is if the backup does not exist then an error
is generated INSIDE the error handling routine. I though i could just proceed
to a second handling routine inside the first one, but VBA generates an error
box instead of trapping the error. Below is the entire code for the sub. Any
ideas out fo this?

Sub checkduplicates()
reddo:
On Error GoTo handler
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfile("q:\workedimorders.txt")
Set ts = f.OpenAsTextStream
Do
u = ts.ReadLine
If u = Sheet1.impno Then GoTo foundyou
Loop
foundyou:
ts.Close
MsgBox "This order has already been imported,checked AND PRINTED. Please be
sure you wish to work it again.", vbCritical, "Repeat!"
Exit Sub
handler:
Select Case Err.Number
Case 53
Err.Clear
On Error GoTo handler1
Set f = fs.getfile("\\station2\lists\workedimorders.txt")
MsgBox "File not found, attempting to copy from backup."
f.Copy "q:\"
GoTo reddo
handler1:
Select Case Err.Number
Case 53
Err.Clear
MsgBox "Backup file is not found, creating new file, all
data on worked files has been lost."
Set a = fs.CreateTextFile("q:\workedimorders.txt", True)
a.writeline (Sheet1.impno)
a.Close
Exit Sub
Case Else
MsgBox "Unknown error retrieving backup, no checks can be
done for this order. Check your connection to drive Q:"
Exit Sub
End Select
Case 55
ts.Close
Err.Clear
GoTo reddo
Case 57
MsgBox "Unable to access database to check status of worked file, check
your connection to Q:\"
Exit Sub
Case 62
ts.Close
Set ts = f.OpenAsTextStream(2, -2)
Do While ts.AtEndOfStream <> True
retstring = ts.ReadLine
Loop
ts.writeline Sheet1.impno
ts.Close
Exit Sub
Case 70
MsgBox "Permission denied to access database. Check your connection
to Q:\"
Exit Sub
Case Else
MsgBox "Unknown error accessing database of worked orders. Continuing to
import."
Exit Sub
End Select
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

Top