delete all tables in a database with macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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
 
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.
 
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.
 
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
 
Tom,

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