delete all tables in a database with macro

A

ABP

I have to delete all tables in my database and then import new ones from a
source. If I try to delete the tables manually then I get a confirm delete
message for each one. This is tedious. If I simply import the tables without
deleting the original ones then the new ones get a numeral appended to the
name. (ex: orders1) This causes problems with my queries.
Any suggestions?
 
F

freakazeud

Hi,
try to adapt VBA...macros are very very limitd and cannot handle error
handling. Here is some sample DAO code which you can use to drop all tables
in a db.

Dim td As DAO.TableDef
For Each td In CurrentDb.TableDefs

DoCmd.DeleteObject acTable, td.Name
Next td

HTH
Good luck
 
S

Steve Schapel

ABP,
I have to delete all tables in my database and then import new ones from a
source. If I try to delete the tables manually then I get a confirm delete
message for each one. This is tedious.

Use Shift+Del to delete manually without the confirmation message.
If I simply import the tables without
deleting the original ones then the new ones get a numeral appended to the
name. (ex: orders1) This causes problems with my queries.
Any suggestions?

Use the DeleteObject action in your macro.
 
F

freakazeud

I personally believe that macros are fairly limited just the fact that you
cannot use error handling would make me not use them.
I would rather see a user adapt VBA and be able to do so much more with
their application. You are correct in this being a macro newsgroup...just
though I would push for widening the OP's horizon.
Thanks Steve.
 
T

Tom Lake

ABP said:
I have to delete all tables in my database and then import new ones from a
source. If I try to delete the tables manually then I get a confirm delete
message for each one. This is tedious. If I simply import the tables
without
deleting the original ones then the new ones get a numeral appended to the
name. (ex: orders1) This causes problems with my queries.

You can eliminate the confirmation messages by adding the following
lines to the macro:

Set Warnings Off
: body of macro
: goes here
:
:
Set Warnings On
 
S

Steve Schapel

Tom,

I don't think there is any confirmation message if you delete the table
in a macro, so no need for the SetWarnings.
 

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