Results 1 to 6 of 6
  1. #1
    easbrandel is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    3

    Question On Error GoTo does not resume?

    I am importing a file into a table with a form and doing some other actions. I am trying to put error handling around the file import. If the file is not there, it should display a message and stop, otherwise continue on. Here is my code (see bold). What happens instead, is if the file is there and imported, it does not proceed to the following statements. What am I doing wrong? Thanks!

    Private Sub Command17_Click()
    On Error Resume Next
    DoCmd.DeleteObject acTable, "ImportErrors"


    On Error GoTo ErrorHandler
    DoCmd.TransferText acImportFixed, "Import Specification", "Table", "C:\file.txt"
    Exit Sub
    ErrorHandler:
    MsgBox ("There was a problem importing the file. Check the filename and try again.")


    Resume Next


    DoCmd.Close acForm, "Form", acSaveYes
    DoCmd.OpenForm "Form"
    On Error Resume Next
    DoCmd.OpenTable "ImportErrors"
    End Sub

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Try putting the ErrorHandler at the very end. I think its treating your docmd's after the Resume Next as part of the Error Handler.

  3. #3
    c_smithwick is offline Underpaid Programmer
    Windows 7 Access 2003
    Join Date
    Jan 2010
    Location
    Lakeside, CA
    Posts
    49
    Resume Next instructs the program to resume at the next line AFTER the one that caused the error, which in your case is "Exit Sub". Try the following:
    Code:
    Private Sub Command17_Click()
    On Error Resume Next
    DoCmd.DeleteObject acTable, "ImportErrors"
    On Error GoTo ErrorHandler
    DoCmd.TransferText acImportFixed, "Import Specification", "Table", "C:\file.txt"
    DoCmd.Close acForm, "Form", acSaveYes
    DoCmd.OpenForm "Form"
    DoCmd.OpenTable "ImportErrors"
    Exit Sub
    ErrorHandler:
     MsgBox ("There was a problem importing the file. Check the filename and try again.")
     Resume Next
    End Sub

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I didn't even notice the exit sub. Good catch C.

  5. #5
    easbrandel is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    3

    Smile

    That did it! Thanks

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    please mark the thread as solved =]

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

Similar Threads

  1. Resume Database
    By RVHII2 in forum Programming
    Replies: 0
    Last Post: 01-20-2009, 05:56 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