Error Handling Issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sthorne
    New Member
    • Dec 2011
    • 2

    #1

    Error Handling Issue

    Has anyone see an issue in an Access 2010 VBA procedure where the second time an error occurs it will return to the calling procedure?

    I have error handling enabled in a procedure and it works fine the first time around, but then the second time an error occurs it will exit the procedure and return to the calling proc.

    I have a routine that loops through some folders and files and tries to move the files. if any of them are in use, then it should skip the file and move the next one.

    Thanks in advance
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It would help to see the code.

    Comment

    • sthorne
      New Member
      • Dec 2011
      • 2

      #3
      Thanks for looking Rabbit... below is the scaled down code. there are some database calls and stuff in the middle but the error handling routines are intact..

      Code:
      [I]Public Sub GetNetworkFiles()
      Dim fs                  As New FileSystemObject
      Dim fld                 As Folder
      
      On Error GoTo GetNetworkFiles_Error
      
      	Set fld = fs.GetFolder(IncomingFolder)
      
      	For Each objFile In fld.Files
      		'move the file
      		fs.MoveFile IncomingFolder & "\" & FileName, OutgoingFolder & "\" & FileName
      	Next
      
      Exit Sub
      
      GetNetworkFiles_Error:
      
          If Err.Number = 70 Then Resume Next'permission denied to the file - most likely file is open
        
          If Err.Number = 53 Then Resume Next 'file not found error - user may have renamed or deleted
      
          If Err.Number = 76 Then 'path not found - folder is missing
              LogAppError Err.Number, Err.Description & "-" & IncomingFolder, "GetNetworkFiles", "mod_Process", Erl
              Resume Next
          End If
          
          LogAppError Err.Number, Err.Description, "GetNetworkFiles", "mod_Process", Erl
      
      End Sub[/I]

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        That typically happens when an error handling routine fails to compete its handling for some reason (EG. returns to main code without a Resume). I see nothing in the posted code that might cause that.

        Comment

        • Mihail
          Contributor
          • Apr 2011
          • 759

          #5
          Or if you have an error inside the error handling routine.
          What is and how work LogAppError ? Is no need to a Resume statement after that ?

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            Originally posted by Mihail
            Mihail:
            Or if you have an error inside the error handling routine.
            That is just one of the situations "when an error handling routine fails to complete its handling". It is not an alternative.

            Originally posted by Mihail
            Mihail:
            What is and how work LogAppError ? Is no need to a Resume statement after that ?
            That could refer to line #23 or #27. I assume you intended to refer to line #27.

            LogAppErr, I would assume, is a procedure defined elsewhere. Line #27 wouldn't require a Resume if the intention is for the procedure (GetNetworkFiles ()) to exit. Such a situation (as the code stands) would not allow any further processing within that procedure anyway, so cannot be what the OP is asking about.

            Comment

            Working...