Results 1 to 8 of 8
  1. #1
    desk4tbc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    29

    Error Coding Problems

    I have a bit of code that is supposed to warn a user twice on unsuccessful deletion of a file.


    Code:
    Exit Sub
    DeleteError:
    If Err.Number > 0 Then
        Err.Clear
        intEmptyFile = MsgBox("Delete was unsuccessful." & vbCrLf & "Please close the file you wish to delete and click OK.", vbExclamation, "Delete Error")
        On Error GoTo DeleteFinal
        Kill OldName
    DeleteFinal:
        If Err.Number > 0 Then
            intEmptyFile = MsgBox("Delete was unsucessful." & vbCrLf & "Please delete the file manually.", vbCritical, "Delete Error")
        End If
        GoTo EOBEntry
    End If
    But for some reason "On Error GoTo DeleteFinal" doesn't work and the script stops at "Kill OldName". This even happens when I replace the "On Error GoTo DeleteFinal" with "On Error Resume Next".

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    How about posting the entire procedure? GoTo's bother me and except for "On Error GoTo", I don't use them.

  3. #3
    desk4tbc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    29
    The requested bit
    Code:
            FileCopy OldName, NewName
            [Link] = NewName & "#" & NewName & "#"
            intDeleteFile = MsgBox(MoreText, vbYesNo, "Delete?")
            If intDeleteFile = vbYes Then
                On Error GoTo DeleteError
                Kill OldName
            End If
    
    EOBEntry:
    If Me.FileType = "EOB" Then
        Application.FollowHyperlink NewName
        intEmptyFile = MsgBox(txt, vbYesNo, "EOB Entries")
        If intEmptyFile = vbYes Then
            DoCmd.OpenForm "FileList_Patient Entry", , , , acFormEdit, , Me.[Accession Number]
        Else
            DoCmd.OpenForm "FileList_Patient Entry", , , , acFormEdit, acWindowNormal
        End If
    End If
    
    Exit Sub
    DeleteError:
    If Err.Number > 0 Then
        Err.Clear
        intEmptyFile = MsgBox("Delete was unsuccessful." & vbCrLf & "Please close the file you wish to delete and click OK.", vbExclamation, "Delete Error")
        On Error GoTo DeleteFinal
        Kill OldName
    DeleteFinal:
        If Err.Number > 0 Then
            intEmptyFile = MsgBox("Delete was unsucessful." & vbCrLf & "Please delete the file manually.", vbCritical, "Delete Error")
        End If
        GoTo EOBEntry
    End If
    
    End Sub
    The GoTo was so that the code could go back to a point before "Exit Sub" and to separate the error coding from the rest of the code.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    So you do not want to post the entire procedure starting with Private Sub... Right? What do you mean the script "stops" at "Kill OldName"? How do you know?

  5. #5
    desk4tbc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    29
    Its a realllllly long sub. Everything else works except the delete error handler part. It gets a Run-time error '70': Permission denied dialog box even though I have an On Error Goto right before the part (line: Kill OldName) that is causing the permission fault.

    I'm wondering what is going on, as the On Error GoTo should be trapped and stored in the Err object but it hasn't.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I take it you have single stepped this code and watched the variables to verify what is happening?

  7. #7
    desk4tbc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    29
    Yep, all the strings, integers and other variables are fine. It just that the On Error isn't working as expected.

    EDIT: Figured it out. Forgot to use resume so I was attempting to do an On Error inside an On Error. Access really didn't like that. Thanks for the help RuralGuy.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You're welcome. Sometimes we're just a sounding board.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Coding question
    By kzoli62 in forum Access
    Replies: 1
    Last Post: 07-04-2011, 05:09 PM
  2. Combo Box Coding
    By Hale in forum Forms
    Replies: 2
    Last Post: 05-04-2010, 10:56 AM
  3. Button Coding
    By yamie in forum Programming
    Replies: 3
    Last Post: 02-22-2010, 10:45 AM
  4. Bar-Coding
    By texasprincess7 in forum Access
    Replies: 1
    Last Post: 02-12-2009, 10:29 AM
  5. Replies: 1
    Last Post: 10-15-2008, 01:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums