Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA runtime error 13 within error handler

Status
Not open for further replies.

anuktac

Technical User
Aug 1, 2002
48
IN
Hi,
I have a function that looks like:

Sub Get_Calls_Data_Build_xxxyyy(Appendix_A, In_file, No_of_Rows, Append_File, Template_Type)
Dim killfile2 As String

On Error GoTo File_Not_Found

killfile2 = ThisWorkbook.Path & "\SomeErr.log"
'Check that file exists
If Len(Dir$(killfile2)) > 0 Then
'First remove readonly attribute, if set
SetAttr killfile2, vbNormal
'Then delete the file
Kill killfile2
End If

(Do stuff which raises error 62: Input past end of file)

File_Not_Found:
Open ThisWorkbook.Path & "\SomeErr.log" For Append As #7
'Open the file for Append
Print #7, Application.Text(Now(), "dd mmm yyyy HH:mm:ss") _
& " " & Err & " " & Error(Err)
Close #7 'Close the log so it can be used again.
Call Auto_Close
End Sub

When it encounters Runtime error 62, it goes into the error-handler and raises another error (Runtime error 13 - type mismatch).
The weird thing is, if I am in debug mode, I don't get this error. But if I am in run-mode, I get this error. On clicking on "Debug" button of the runtime error, it quits the application, so I can never see which line is causing the error.

Any ideas, folks? What is wroong here? Why am I getting the runtime error 13?

-Anukta
 
I don't immediately see the problem. To troubleshoot, you could change your code to:

File_Not_Found:
Resume ErrorHandler
ErrorHandler:
on error goto 0

(rest of your code for logging the error here)

That way, you're not inside an error handler when the second error hits, and hopefully you won't be tossed out of the application so you can better troubleshoot.
Rob
[flowerface]
 
Well,
I still kept getting the same error. But I got around it somehow. There was a main function which was calling this function I have written above. On putting the error handler in the main function, and removing it from the called function, the error properly got trapped without raising a second error.
I am still mystified tho' why it should have happened.[ponder]

-Anukta
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top