Delete table in a Report

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
 
J

John Spencer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top