Delete table in a Report

  • Thread starter Thread starter Sarah
  • Start date Start date
S

Sarah

Does anyone know how to delete a table that is being used by a report after
the user previews the report, then closes the report? I tried using the
onclose event to delete the table, but the error states it's still in use.
This is a table that is created on the fly with a random name and I don't
want it to reside in the database after it's been used.

Thanks for any suggestions.

Sarah
 
If you are calling the report from VBA code then you could use something like
the code below. It is going to consume a LOT of resources, but it should work.

DoCmd.OpenReport "SomeReport", acViewPreview

While CurrentProject.AllReports("rpt_ProjectOverview").IsLoaded
DoEvents
Wend

CurrentDb().TableDefs.Delete "SomeTable"

You can use the sleepApi to make this a bit more efficient. See
http://www.mvps.org/access/api/api0021.htm


John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
 
Back
Top