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

ADO to delete linked sql tables requires multiple passes

Status
Not open for further replies.

glgcag1991

Programmer
Oct 15, 2007
72
US
I am writing code to delete links to my SQL Server tables and when I run the function, it doesn't delete all the tables. I have a total of 89 linked SQL tables and I have to run the function 5 times to delete all the tables. Here's the code I'm running:

Code:
Function DeleteSQLTableLinks()
    'On Error Resume Next
    Dim cn As New ADODB.Connection
    Dim cat As New ADOX.Catalog
    Dim tbl As New ADOX.Table
    Dim lCnt As Long
    'Types of tables: TABLE=Access mdb table; ACCESS TABLE=Access mdb system table
    'VIEW=Access mdb query; PASS-THROUGH=SQL Server linked table
    cn.ConnectionString = CurrentProject.Connection
    cn.Open
    cat.ActiveConnection = cn
    lCnt = 0
    For Each tbl In cat.Tables
        If tbl.Type = "PASS-THROUGH" Then
            lCnt = lCnt + 1
            Debug.Print lCnt & ". " & tbl.Name & " --- " & tbl.Type
            cat.Tables.Delete (tbl.Name)
            cat.Tables.Refresh
        End If
    Next tbl
    cn.Close
    Set cn = Nothing
    Set cat = Nothing
End Function

Any help is appreciated!
 
I removed the tables.refresh and it is still doing the same thing. What do you mean by counting the tables and then stepping through them from end to beginning? I can do it with a recordset but I can't with the cat.tables collection, at least that I know of.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top