Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to delete tables from code? 1

Status
Not open for further replies.

sabavno

Programmer
Jul 25, 2002
381
CA
Hello,

I was wondering if anyone could tell me how to delete the tables using VBA?

The trick is I woulnd't know the exact names of the tables. I would want to delete all the tables that contain "Errors" in their names.

Please advise.

Thanks.
 
I'll try to get you started.

dim db as database
dim tdf as tabledef

set db = currentdb

For each tdf in db.tabledefs
If tdf.Name = (your parameters here for name or name contains xxx)
db.execute "DROP TABLE xyz;" 'you will need to identify your table name here
Endif
Next tdf

You will need error handling. Look under Access help for tabledef, drop, etc for further information. Also, do a search in this forum for articles - there are many.
 
evalesthy, you were so close! Just a few changes to the for/each structure:

For each tdf in db.tabledefs
If tdf.Name like "*errors*" then
db.execute "DROP TABLE " & tdf.name
End if
Next tdf

Jeremy
=============
Jeremy Wallace AlphaBet City Dataworks
See the Developers' section for some helpful fundamentals.

See thread181-473997 for information on how to get the best responses possible here at Tek-Tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top