[AccessD] Finding & Deleting A Table Using ADO

paul.hartland at fsmail.net paul.hartland at fsmail.net
Fri Apr 21 05:06:40 CDT 2006


Thanks Gustav, but can't just delete the table as it's it a function and you pass the name of the table to the function, can be one of three, so I came up with this:
Function CheckTables(strName As String) As Integer
    ' **** Use This Function To Check For Existing Table Before Import, If Exists Then Delete It ****
    Dim catOpen As New ADOX.Catalog
    Dim tblFind As ADOX.Table
    
    Set catOpen.ActiveConnection = CurrentProject.Connection
    
    For Each tblFind In catOpen.Tables
        If (tblFind.Name = strName) Then
            catOpen.Tables.Delete tblFind.Name
            'MsgBox tblFind.Name
        End If
    Next tblFind
    
    Set tblFind = Nothing
    Set catOpen = Nothing
End Function





Message Received: Apr 21 2006, 11:02 AM
From: "Gustav Brock" 
To: accessd at databaseadvisors.com
Cc: 
Subject: Re: [AccessD] Finding & Deleting A Table Using ADO

Hi Paul

Why not just delete the table:

Function DeleteTable()

Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table

cat.ActiveConnection = CurrentProject.Connection
On Error Resume Next
Set tbl = cat.Tables("schednew")
If Err.Number = 0 Then
cat.Tables.Delete tbl.Name
End If

Set tbl = Nothing
Set cat = Nothing

End Function


>>> paul.hartland at fsmail.net 21-04-2006 11:26 >>>
To All,
I am without success trying to write some code using ADO (Access XP) in a function which will loop through all the tables I have and if a particular table (schednew) exists then delete it.
Can anyone please provide some sample code or point me in the right direction to do this, as I am suffering from a Friday brain dead moment I think.
Thanks for any help in advance.
Paul Hartland

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


s


More information about the AccessD mailing list