[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 720
  • Last Modified:

File already open

I recently added an Add-On entitled "MouseWheel Fix".  Since doing that my On Error routines no longer work.  I went to MSDN On Error statement and added the Code Snippet shown below to my code.  When executed, I get a "File already open" error message at the Kill "TESTFILE" line.  Program control ignores the error handler routine.  The code I use in my applications is very similiar to the OnErrorStatementDemo shown below.  Neither of them work.  Am I doing something wrong or has the Add-On somehow affected my system?
Sub OnErrorStatementDemo()
  Dim objectref As Object
  Dim msg As String
   On Error GoTo ErrorHandler   ' Enable error-handling routine.
   Open "TESTFILE" For Output As #1   ' Open file for output.
   Kill "TESTFILE"   ' Attempt to delete open
            ' file.
   On Error GoTo 0   ' Turn off error trapping.
   On Error Resume Next   ' Defer error trapping.
   objectref = GetObject("MyWord.Basic")   ' Try to start nonexistent
            ' object, then test for
'Check for likely Automation errors.
   If Err.Number = 440 Or Err.Number = 432 Then
      ' Tell user what happened. Then clear the Err object.
      msg = "There was an error attempting to open the Automation object!"
      MsgBox msg, , "Deferred Error Test"
      Err.Clear   ' Clear Err object fields
   End If
Exit Sub      ' Exit to avoid handler.
ErrorHandler:   ' Error-handling routine.
   Select Case Err.Number   ' Evaluate error number.
      Case 55   ' "File already open" error.
         Close #1   ' Close open file.
      Case Else
         ' Handle other situations here...
   End Select
   Resume   ' Resume execution at same line
            ' that caused the error.
End Sub

Open in new window

0
2top
Asked:
2top
  • 2
  • 2
1 Solution
 
ee_rleeCommented:
did you try to add a breakpoint to check if the error handler works?
0
 
2topAuthor Commented:
Thanks for your response!  Yes, I stopped on the On Error statement and stepped the next two statements.  It errs on the Kill statement but never goes to the ErrorHandler routine.
0
 
ee_rleeCommented:
maybe you have turned on break on all error

IDE Options
These options only work when your program is running in the IDE. They have no bearing on your compiled code. To select the required option from the IDE main menu select Tools, Options & then the General tab. There are 3 options to handle Error Trapping.

Break On All Errors
Tells your application to stop execution at the point of the error, even if you have coded an error handling routine. Generally you will use this option if you are trying to track down a specific error.
0
 
2topAuthor Commented:
I didn't fully understand the options on the General tab.  It seemed to me that Break on all Errors was correct.  It was set that way and I changed it to Break on Unhandled Errors and now my Error Handling works!  Thank you!!
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now