Deleting Tables

E

Edgar Thoemmes

How can I delete all table in a database except for tblTEMPIMPORT and
tblSuppliers?
 
D

Douglas J. Steele

Something like the following should work:

Dim dbCurr As DAO.Database
Dim tdfCurr As DAO.TableDef
Dim intLoop As Integer

Set dbCurr = CurrentDb()
For intLoop = (dbCurr.TableDefs.Count - 1) To 1 Step -1
Set tdfCurr = dbCurr.TableDefs(intLoop)
If (tdfCurr.Attributes And dbSystemObject) = 0 Then
If tdfCurr.Name <> "tblTEMPIMPORT" And _
tdfCurr.Name <> "tblSuppliers" Then
dbCurr.TableDefs.Delete tdfCurr.Name
End If
End If
Next intLoop

Set dbCurr = Nothing


(Of course, if there are relationships set up between the tables, you'll
probably run into problems)
 

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