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

Deleting Import Error Tables automatically 1

Status
Not open for further replies.

newcoder54

Technical User
Jul 2, 2002
46
US
How can I delete tables using code? Need to delete tables that result from less than perfect imports. The table names all start the same name of coase but end with 1,2,3 etc. Or to be exact: Brecksville$_ImportErrors1, Brecksville$_ImportErrors2,
Brecksville$_ImportErrors3
etc etc

Thanks for helping me get rid of this annoyance.
 
Sub delimport()

Dim db As DAO.Database
Dim tbl As TableDef
Set db = CurrentDb()
Set tbl = New TableDef
For Each tbl In db.TableDefs
If tbl.Name Like "*$_ImportErrors*" Then
DoCmd.DeleteObject acTable, tbl.Name
End If
Next tbl
db.TableDefs.Refresh

End Sub
 
second version :

Sub adoxdel()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
cat.ActiveConnection = CurrentProject.Connection
For Each tbl In cat.Tables
If tbl.Name Like "*$_ImportErrors*" Then
cat.Tables.Delete tbl.Name
DoCmd.DeleteObject acTable, tbl.Name
End If
Next tbl
End Sub
 
second version :

Sub adoxdel()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
cat.ActiveConnection = CurrentProject.Connection
For Each tbl In cat.Tables
If tbl.Name Like "*$_ImportErrors*" Then
cat.Tables.Delete tbl.Name
End If
Next tbl
End Sub
 
Wow - pretty neat and ready to just past in. I really appreciate this more than you might think!!!!

Larry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top