Deleting temporary tables.

speedosteve

New member
Local time
Today, 05:15
Joined
Mar 15, 2004
Messages
4
I'm working on a database for a bowling tournament.
For each event, I've code written that calculates totals, ranks them in order of place, divides up and assigns prize money, then pulls all of this into a neat little package.

Trouble is I dump some of the information into temporary tables during the process. For example, the score totals are held in tbl01 until the prize money is finished calculating.

If an error occurs and the temporary table tbl01 is still there, I get an error that tells me the table already exists and won't let me run the code. What I'm looking for is code (if any) to see if the process can pick up any temporary tables that are present and delete them when the error code kicks in to prevent messages like this. To summarize:

Err_SinglesEvent:

if tbl01 exists, then
delete it (docmd.deleteobject actable, "tbl01")
end if

Any suggestions on code that would help me if the table exists already?
Any help would be appreciated.
Thanks.
 
Just use some code like this in your program:
Code:
Sub DeleteTempTables()
    On Error Resume Next
    Currentdb.TableDefs.Delete "tablename"
End Sub
Just add mroe Currentdb.TablesDefs.Delete statements for every table you want to delete, if it exists.

The On Error Resume Next command turns off error checking for that procedure and tells the program to just move onto the next line if an error occurs. In this case, if you try to delete a table, and it doesn't exist, Access would otherwise give you an error message. You just want Access to delete the table, and not say anything if the table doesn't already exist.
 

Users who are viewing this thread

Back
Top Bottom