Consulting

Results 1 to 4 of 4

Thread: Drop TempTable whener sub puits running

  1. #1

    Drop TempTable whener sub puits running

    I create a temptable to hold data for a report, then drop it after report is generated. It work fine. What I need now is to drop the temptable whener the Sub stopping running regardless, e.g got error or in middle of debugging. Can DoCmd do that?

    Any help is appreciated. Thanks

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    Personally, I use DDL to handle table actions. An example would be:
    [VBA]DoCmd.RunSQL "DROP TABLE TableName"[/VBA]
    The above example will delete the named table. Just replace TableName with the table's actual name.

    What I need now is to drop the temptable whener the Sub stopping running regardless, e.g got error or in middle of debugging.
    You need to setup some error trapping to handle this. Example:
    [VBA]Sub SubName()
    'variable declarations
    On Error GoTo ErrorHandler
    'code you want to run
    DoCmd.RunSQL "DROP TABLE TableName"
    Exit Sub

    ErrorHandler:
    DoCmd.RunSQL "DROP TABLE TableName"
    End Sub[/VBA]

    HTH
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    Quote Originally Posted by CreganTur
    You need to setup some error trapping to handle this. Example:
    [vba]Sub SubName()
    'variable declarations
    On Error GoTo ErrorHandler
    'code you want to run
    DoCmd.RunSQL "DROP TABLE TableName"
    Exit Sub

    ErrorHandler:
    DoCmd.RunSQL "DROP TABLE TableName"
    End Sub[/vba]

    HTH
    Randy, Thanks for your help.

    What if during the debug, I want to quit the program by click on stop (reset) buttom after the temptable is created? How do I set up error trapping on that?

  4. #4
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    What if during the debug, I want to quit the program by click on stop (reset) buttom after the temptable is created? How do I set up error trapping on that?
    You can't. You'll need to delete the table by hand, or have a sub in a module that you can run to delete the table for you.

    Errors only respond to program errors. Manually stopping your code when debugging is not an error.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


Posting Permissions

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