Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Sep 2008
    Location
    Liverpool, Merseyside, United Kingdom
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with On Error Resume Next (2003)

    Recently upgraded from 97 to 2003 and the following code (which I've used forever) now produces an error message, can anyone please help?

    Sub Test()

    On Error Resume Next
    DoCmd.DeleteObject acTable, "TestTable"
    On Error GoTo 0

    End Sub

    The table "TestTable" doesn't exist, although it might in the future, in which case I want to delete it.

    Had a look at the online Help and tried:

    Sub Test2()

    On Error GoTo ErrorHandler
    DoCmd.DeleteObject acTable, "TestTable"
    On Error GoTo 0

    ErrorHandler:
    Resume Next

    End Sub

    ... but that also produced the same error: RunTime Error 7874 - Microsoft Office Access can't find the object 'TestTable'

    Am I doing something really stupid here?
    Many thanks for reading.
    Irene

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Problem with On Error Resume Next (2003)

    Both versions of the code are correct. I suspect the error message is caused by the Error Trapping setting:
    <UL><LI>In the Visual Basic Editor, select Tools | Options...
    <LI>Activate the General tab.
    <LI>Look at the option selected in the Error Trapping section. If it's set to "Break on All Errors", you'll get an error message for all errors, even if you try to suppress them using an error handler or On Error Resume Next.
    <LI>The preferred option is "Break on Unhandled Errors" - see screenshot below. This will suppress error messages if you have an error handler or On Error Resume Next.
    <LI>Click OK to confirm the setting and close the dialog.[/list]HTH
    Attached Images Attached Images
    • File Type: jpg x.jpg (26.5 KB, 0 views)

  3. #3
    New Lounger
    Join Date
    Sep 2008
    Location
    Liverpool, Merseyside, United Kingdom
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem with On Error Resume Next (2003)

    Thank you very much for the help Hans, that's worked a treat.
    Regards
    Irene

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •