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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete all tables 1

Status
Not open for further replies.

peljo

Technical User
Mar 3, 2006
91
BG
I have a function that deletes all the tables in the database.However i do not want to delete the tables TblSpecial1 and TblSpecial2.How can i rewrite the code ?
Public Function DeleteTables()
Dim dbs As DAO.Database
Dim i As Integer
Set dbs = CurrentDb
' Loop backwards through relations
For i = dbs.Relations.Count - 1 To 0 Step -1
dbs.Relations.Delete dbs.Relations(i).Name
Next i
' Loop backwards through tabledefs
For i = dbs.TableDefs.Count - 1 To 0 Step -1
If Left(dbs.TableDefs(i).Name, 4) <> "MSys" Then
dbs.TableDefs.Delete dbs.TableDefs(i).Name
End If
Next i
Set dbs = Nothing
End Function
 
You can use the same idea:

Code:
For i = dbs.TableDefs.Count - 1 To 0 Step -1
If Left(dbs.TableDefs(i).Name, 4) <> "MSys" _
  And Left(dbs.TableDefs(i).Name, 10) <> "TblSpecial" Then
  dbs.TableDefs.Delete dbs.TableDefs(i).Name
End If
Next i
Set dbs = Nothing
End Function
 
Thank you ! it is all fine now !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top