Results 1 to 7 of 7
  1. #1
    nhabegger is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    3

    Delete Table on Report_Close

    I am showing my users a report (rptAnimations) which displays the data in a table (tblAnimationReport). I want to delete the table on Report_Close. I've tried using DoCmd.DeleteObject, but I get the following message:

    Run-time Error '3211':
    The database engine could not lock table 'tblAnimationReport' because it is already in use by another person or process.


    Here is my code:



    Code:
    Private Sub Report_Close()
     
      DoCmd.DeleteObject acTable, "tblAnimationReport"
    
    End Sub
    The tblAnimationReport is created using a Make Table query. Here is the code related to the control which runs that query and displays the report off a button control on a form.

    Code:
    Sub Command9_Click()
    
      DoCmd.OpenQuery "qryMakeAnimationReport", acViewNormal, acEdit
        
      DoCmd.Close acForm, "frmMakeAnimationReport"
      
      DoCmd.OpenReport "rptAnimationReport", acViewPreview
      
    End Sub
    Let me know if you need more information. Thanks in advance.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you won't be able to do it. deleting a table requires the data not be in use anywhere else. the data is in use until all the report's events are bypassed. thus, "on-close" means the data is still being used

  3. #3
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You could delete the old table before creating the new one. So you would put the delete command before the make table command.

  4. #4
    nhabegger is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    3
    Thanks for the replies.

    I think I may be able to solve this by using two control buttons on my form. The first will allow the user to view the report using:

    Code:
     DoCmd.OpenReport "rptAnimationReport", acViewPreview
    The second button will print the report using:

    Code:
     DoCmd.OpenReport "rptAnimationReport", acViewNormal
    Once the report is printed, I can delete the table. I will also delete the table during the On_Close event of the form, which will allow me to get rid of the table if the user only views the report.

    Thanks again for the input, everyone!

  5. #5
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    What happens if the user closes the for while the report is still open? I don't see how that is different from your initial situation. Please let us know if your plan is successful.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Generally speaking, it would be more efficient to delete records from and then add records to a table, rather than delete/recreate the table itself. In other words, an append query instead of a make table query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Join Date
    May 2010
    Posts
    339
    nhabegger,

    Check out Maximus soultion to a similar question.

    https://www.accessforums.net/program...able-6291.html

    He uses the forms close event, and then unbinds the record source.

    Richard

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

Similar Threads

  1. Delete button with archive Table
    By tlyons in forum Forms
    Replies: 4
    Last Post: 07-08-2010, 12:18 PM
  2. Replies: 1
    Last Post: 04-29-2010, 05:22 PM
  3. Delete duplicates within one table
    By zbreima in forum Access
    Replies: 1
    Last Post: 01-28-2010, 06:49 PM
  4. Replies: 0
    Last Post: 08-25-2008, 12:17 PM
  5. Delete all records in a table?
    By bob646 in forum Access
    Replies: 1
    Last Post: 05-20-2007, 11:41 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