PSUIVERSON
Technical User
I wrote some VBA that will delete all tables at the beginning of each month before running all my imports and queries etc. to setup monthly tables etc. I DO NOT WANT TO DELETE TWO TABLES so I wrote some VBA using ADOX to do this...Very weird problem is occurring that I need some help on. When I run this code and to a breakpoint and trap the tablename count and tblName at certain points it's returning table names that I do not have or too large count. For example - I manually deleted all the tables but TABLE1 and TABLE2. So theoretically when going through the code it should have a tbl.count = 2 and tblNames should be those two when checking. However I am getting a table count = 9 and names such as "MySysAccessObjects" going through. What is this?
HERE IS THE CODE:
Function Cleanup___Pre_Monthly_Conversion()
On Error GoTo Cleanup_Err
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim tblName As String
Dim tableExists As Boolean
Dim i As Integer
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
i = cat.Tables.count
For Each tbl In cat.Tables
tblName = tbl.Name
If tblName <> "TABLE1" And tblName <> "TABLE2" Then
cat.Tables.Delete (tbl.Name)
Else
MsgBox ("We cannot delete the following table " & tbl.Name & " ."
End If
Continue:
Next
MsgBox """Clean Up Completed. You may now begin the monthly conversion process.""", vbOKOnly, ""
Cleanup_Err:
MsgBox Error$
Resume Continue
End Function
HERE IS THE CODE:
Function Cleanup___Pre_Monthly_Conversion()
On Error GoTo Cleanup_Err
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim tblName As String
Dim tableExists As Boolean
Dim i As Integer
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
i = cat.Tables.count
For Each tbl In cat.Tables
tblName = tbl.Name
If tblName <> "TABLE1" And tblName <> "TABLE2" Then
cat.Tables.Delete (tbl.Name)
Else
MsgBox ("We cannot delete the following table " & tbl.Name & " ."
End If
Continue:
Next
MsgBox """Clean Up Completed. You may now begin the monthly conversion process.""", vbOKOnly, ""
Cleanup_Err:
MsgBox Error$
Resume Continue
End Function