How to Remove ALL linked Tables from Access2k3 ?

  • Thread starter Thread starter Techie
  • Start date Start date
T

Techie

Hi All!!

Any suggestions on how to remove all of the linked tables at once???

I know of the default menu system (Tools/Database Utilities/Linked Table
Manager)

I also know about the Macro control...
Action: DeleteObject
Object Type: Table
Object Name: MyTable

At 1 macro per table.. it takes a few macros to remove all of my linked
tables.

I then run a Docmd to run each macro... (Again.. thats a lot of code)

Thanks in Advance..
 
Assuming you've got a reference set to DAO, you can use code like:

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

Set dbCurr = CurrentDb()
For intLoop = (dbCurr.TableDefs.Count - 1) To 0 Step -1
Set tdfCurr = dbCurr.TableDefs(intLoop)
If Len(tdfCurr.Connect) > 0 Then
dbCurr.TableDefs.Delete tdfCurr.Name
End If
Next intLoop

Set dbCurr = Nothing
 
Actually, if you don't refresh the tabledefs collection,
it doesn't matter which way you go around the loop:

dim tdf as object
dim tdfs as object

Set tdfs = codedb.tdfs
For each tdf in tdfs
if len(tdf.connect) > 0 then tdfs.delete tdf
next

(david)
 
You sure about that, David?

I haven't tested recently, but I thought that when you deleted a table, the
pointer in the TableDefs collection moved to the next TableDef object (since
where it was pointing no longer existed). Then, when you hit the next For
Each, it moves to the next TableDef object again, thereby ignoring every
other table.
 
Well, I could claim that I only tested it on a sparse
collection, but then if I'd tested it, I wouldn't have
written this:

tdfs.delete tdf

:~(

It obviously DOES refresh after every delete.

(david)
 

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

Back
Top