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

Delete linked table if no records

Status
Not open for further replies.

UHNSTrust

Technical User
Dec 2, 2003
262
GB
I have just created an ODBC and linked over 1000 tables. However for ease of use I want to be able to delete all of the tables where there are no records (100s). Can someone advise me of how to do this with code in a module?

Thanks in advance
Jonathan
 
Code:
Dim mydb As Database

Dim tbdefs As TableDefs
Dim tbdef As TableDef
Set mydb = CurrentDb
Set tbdefs = mydb.TableDefs

For Each tbdef In tbdefs
    If DCount("*", tbdef.Name) = 0 Then
        mydb.Execute "drop table " & "tbdef.Name"
    End If
Next
 
Hi pwise,

Worked perfectly with a bit of playing for timeouts to the DCount.

Thanks
Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top