473,396 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem deleteing linked tables

b b

I created the following code to delete all linked tables in my database
(Access 200):

--------------------------------------------------------
Dim tbl As TableDef

Dim dbs As Database
Set dbs = CurrentDb

For Each tbl In dbs.TableDefs
If Len(tbl.Connect) > 0 Then ' Is a linked table
Debug.Print "Deleting table " & tbl.name & " ... "
dbs.TableDefs.Delete tbl.name
End If
Next tbl

---------------------------------------------------------

When I execute the code it goes through the collection of tables and
deletes "some" of the linked tables.

If I execute the code again, it again deletes "some" of the linked
tables.

Thus, in order to delete all linked tables I have to execute this code
several times.

My question is, since I'm using the connection string to determine if
the table is a linked table, then why does it return true some times and
false on other times for the same table? I'm assuming this is what is
happening as it is the only thing that makes sense.

Thanks for your help.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #1
5 5074
b b,

When you delete the table, it removes it from the collection, so when you go
to the next table, you skip one.

Let's say you have four tables:
Table 1
Table 2
Table 3
Table 4

You delete table 1, and then move to table 2, but since you deleted table 2,
table 3 is now table 2, and table 2 is now table 1, and you've just skipped
past table 2. So if you run your code on these four tables, it'll delete
table 1 and table 3 and leave table 2 and 4. Run it again and you'll delete
table 2 and leave table 4. Run it a third time, and you'll get rid of table
3.

Make sense? :o)

--
Jeremy Shapiro
Asandia, Corp.
www.asandia.com
1.866.ASANDIA (272.6342)
"b b" <bb********@barrlabs.com> wrote in message
news:40*********************@news.newsgroups.ws...

I created the following code to delete all linked tables in my database
(Access 200):

--------------------------------------------------------
Dim tbl As TableDef

Dim dbs As Database
Set dbs = CurrentDb

For Each tbl In dbs.TableDefs
If Len(tbl.Connect) > 0 Then ' Is a linked table
Debug.Print "Deleting table " & tbl.name & " ... "
dbs.TableDefs.Delete tbl.name
End If
Next tbl

---------------------------------------------------------

When I execute the code it goes through the collection of tables and
deletes "some" of the linked tables.

If I execute the code again, it again deletes "some" of the linked
tables.

Thus, in order to delete all linked tables I have to execute this code
several times.

My question is, since I'm using the connection string to determine if
the table is a linked table, then why does it return true some times and
false on other times for the same table? I'm assuming this is what is
happening as it is the only thing that makes sense.

Thanks for your help.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #2
Try refreshing the tabledefs collection first:

Dim dbs As Database
Set dbs = CurrentDb
dbs.Tabledefs.Refresh
For each ...
Next

Arno R

"b b" <bb********@barrlabs.com> schreef in bericht
news:40*********************@news.newsgroups.ws...

I created the following code to delete all linked tables in my database
(Access 200):

--------------------------------------------------------
Dim tbl As TableDef

Dim dbs As Database
Set dbs = CurrentDb

For Each tbl In dbs.TableDefs
If Len(tbl.Connect) > 0 Then ' Is a linked table
Debug.Print "Deleting table " & tbl.name & " ... "
dbs.TableDefs.Delete tbl.name
End If
Next tbl

---------------------------------------------------------

When I execute the code it goes through the collection of tables and
deletes "some" of the linked tables.

If I execute the code again, it again deletes "some" of the linked
tables.

Thus, in order to delete all linked tables I have to execute this code
several times.

My question is, since I'm using the connection string to determine if
the table is a linked table, then why does it return true some times and
false on other times for the same table? I'm assuming this is what is
happening as it is the only thing that makes sense.

Thanks for your help.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #3
"Arno R" <ar****************@tiscali.nl> wrote in
news:40**********************@dreader2.news.tiscal i.nl:
Try refreshing the tabledefs collection first:

Dim dbs As Database
Set dbs = CurrentDb
dbs.Tabledefs.Refresh
For each ...
Next

Arno R

I seem to recall that this is an issue with the bookmark bug.
Essentially when the record is deleted, the pointer index
increments by one but the records move down by one, leaving
undeleted records.

Try coding a for-next that starts at tabledefs.count and working
backwards to 0

Bob Quintal

"b b" <bb********@barrlabs.com> schreef in bericht
news:40*********************@news.newsgroups.ws...

I created the following code to delete all linked tables in
my database (Access 200):

--------------------------------------------------------
Dim tbl As TableDef

Dim dbs As Database
Set dbs = CurrentDb

For Each tbl In dbs.TableDefs
If Len(tbl.Connect) > 0 Then ' Is a linked table
Debug.Print "Deleting table " & tbl.name & " ... "
dbs.TableDefs.Delete tbl.name
End If
Next tbl

---------------------------------------------------------

When I execute the code it goes through the collection of
tables and deletes "some" of the linked tables.

If I execute the code again, it again deletes "some" of the
linked tables.

Thus, in order to delete all linked tables I have to execute
this code several times.

My question is, since I'm using the connection string to
determine if the table is a linked table, then why does it
return true some times and false on other times for the same
table? I'm assuming this is what is happening as it is the
only thing that makes sense.

Thanks for your help.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



Nov 13 '05 #4
Each time you delete a linked table you muck up the 'For Each' clause
because the number of items in the collection changes.

The code below is more predictable because it only does one deletion with
each pass through the collection.
If anything, it's overly cautious, but reliable.

Public Sub DetachAllTables()
Dim tdf As TableDef
Dim tdfs As TableDefs
Dim linked_table_found As Boolean

Set tdfs = DBEngine(0)(0).TableDefs
Do
linked_table_found = False
For Each tdf In tdfs
If (tdf.Attributes And dbAttachedTable) = dbAttachedTable Then
tdfs.Delete tdf.Name
linked_table_found = True
Exit For 'exit loop and start again from top
End If
Next tdf
tdfs.Refresh
Loop Until Not linked_table_found
End Sub

Ian.

"b b" <bb********@barrlabs.com> wrote in message
news:40*********************@news.newsgroups.ws...

I created the following code to delete all linked tables in my database
(Access 200):

--------------------------------------------------------
Dim tbl As TableDef

Dim dbs As Database
Set dbs = CurrentDb

For Each tbl In dbs.TableDefs
If Len(tbl.Connect) > 0 Then ' Is a linked table
Debug.Print "Deleting table " & tbl.name & " ... "
dbs.TableDefs.Delete tbl.name
End If
Next tbl

---------------------------------------------------------

When I execute the code it goes through the collection of tables and
deletes "some" of the linked tables.

If I execute the code again, it again deletes "some" of the linked
tables.

Thus, in order to delete all linked tables I have to execute this code
several times.

My question is, since I'm using the connection string to determine if
the table is a linked table, then why does it return true some times and
false on other times for the same table? I'm assuming this is what is
happening as it is the only thing that makes sense.

Thanks for your help.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #5
It's much simpler to go through the collection from the end:

Public Sub DetachAllTables()
Dim tdf As TableDef
Dim tdfs As TableDefs
Dim intLoop As Integer

Set tdfs = DBEngine(0)(0).TableDefs
For intLoop = (tdfs.TableDefs.Count - 1) To 0 Step -1
Set tdf = tdfs(intLoop)
If (tdf.Attributes And dbAttachedTable) = dbAttachedTable Then
tdfs.Delete tdf.Name
End If
Next intLoop

End Sub
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Ian Hinson" <pp******@bigpond.net.au> wrote in message
news:9e******************@news-server.bigpond.net.au...
Each time you delete a linked table you muck up the 'For Each' clause
because the number of items in the collection changes.

The code below is more predictable because it only does one deletion with
each pass through the collection.
If anything, it's overly cautious, but reliable.

Public Sub DetachAllTables()
Dim tdf As TableDef
Dim tdfs As TableDefs
Dim linked_table_found As Boolean

Set tdfs = DBEngine(0)(0).TableDefs
Do
linked_table_found = False
For Each tdf In tdfs
If (tdf.Attributes And dbAttachedTable) = dbAttachedTable Then
tdfs.Delete tdf.Name
linked_table_found = True
Exit For 'exit loop and start again from top
End If
Next tdf
tdfs.Refresh
Loop Until Not linked_table_found
End Sub

Ian.

"b b" <bb********@barrlabs.com> wrote in message
news:40*********************@news.newsgroups.ws...

I created the following code to delete all linked tables in my database
(Access 200):

--------------------------------------------------------
Dim tbl As TableDef

Dim dbs As Database
Set dbs = CurrentDb

For Each tbl In dbs.TableDefs
If Len(tbl.Connect) > 0 Then ' Is a linked table
Debug.Print "Deleting table " & tbl.name & " ... "
dbs.TableDefs.Delete tbl.name
End If
Next tbl

---------------------------------------------------------

When I execute the code it goes through the collection of tables and
deletes "some" of the linked tables.

If I execute the code again, it again deletes "some" of the linked
tables.

Thus, in order to delete all linked tables I have to execute this code
several times.

My question is, since I'm using the connection string to determine if
the table is a linked table, then why does it return true some times and
false on other times for the same table? I'm assuming this is what is
happening as it is the only thing that makes sense.

Thanks for your help.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: michael | last post by:
Gotta post because this is driving me nuts. Trying to DELETE orphans. I can successfully: SELECT GroupID FROM Groups LEFT JOIN Users ON UsersID = UserID WHERE UsersID IS NULL; but when I...
2
by: Robert McGregor | last post by:
Hi all, I've got a Front End / Back End database that was working just fine. One day i opened the FE to find that if I tried to open one of the linked tables from the database window, nothing...
3
by: Michael Plant | last post by:
Hello one and all. I have a stored table in my database and the form I'm using is based on a query that draws data from my stored table and a linked table. The linked table is a *.txt file. ...
2
by: DataB | last post by:
Hi everyone! I have a forms problem. Bakground: I have created a number of tables. Of these, I have a main parent table (Personal Details) and a number of other child tables (Tax file No.,...
4
by: Neil Ginsberg | last post by:
I have ODBC linked tables to a SQL 7 database in an A2K database. The linked tables do not have the password stored in them, so the first time the user accesses them, they need to enter the SQL...
8
by: Alfonso Esteban Gonzalez Sencion | last post by:
I am trying to use Access as a front end for extracting information from an Oracle database. I started using linked tables but I am getting a very curious behaviour. When I consult the linked...
6
by: RBohannon | last post by:
I'm using Access 2000. I have a DB with 19 tables, and I have just split it. When I look in the back end, all 19 tables are there. However, only 17 of them in the front end are actually linked to...
4
by: pokerboy801 | last post by:
OK, I will try to explain this as clearly and as concise as possible. I am using Access, which has three MS Excel Linked tables, to store call center metrics for reps. My Excel workbook has three...
4
by: Mike | last post by:
I have a multiuser access database to which I have split into fe & be. The system refreshes the links at each log-on between the fe & be automatically via code. PROBLEM: Locally it runs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.