Check existence of table in macro

  • Thread starter Thread starter Serena
  • Start date Start date
S

Serena

Hi

Using Access 97.

I have a macro which imports a couple of spreadsheets into
two different tables. Because I don't want to append the
data, I want to be able to delete the applicable tables
before the import. If for some reason the tables don't
exist (e.g. previous import fell over halfway through) I
get an error.

Is there some expression I can put in a condition to check
the table existence before deleting ? - the only thing I
can find in the knowledgebase is Article 113549 which
requires creating a new function to do this.

Failing that, is there a better way of doing the import ?

Thank you in advance
Serena
 
Is there really a need to delete the table? Is the format of the table
different for each spreadsheet?

Assuming that the format is the same, just create a table to receive the
data and keep it in your database.

Then import your data into it, use an append query to copy the data into the
permanent table, then run a delete query to empty that first table. It's now
ready for the next one.

If you really need to delete the table, then you'll need to use VBA code to
trap the error that will occur if you try to delete the table and it's not
in existence.

Or you can use the example in the KB article that you cited to check for the
existence of the table (this function could be called from a macro).

Or you could use the VBA code shown here (
http://www.mvps.org/access/tables/tbl0001.htm ) to determine if the table
exists. This function could be called from a macro.
 
Thanks Ken, of course using the delete query to empty the
table is much the easiest way to go, duh !

It's just frustrating that there isn't an existing
function to check existence of an object !
 
Back
Top