Re: strange behavior by deleting tables

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Thu, 5 Apr 2007 23:39:27 +0200, "Cesar Romani" <cesar_romani@xxxxxxxx> wrote:

¤ I've written the following code to delete all tables of a ms access db.
¤ It deletes only half the number of tables not all.
¤ ----------------------------------------
¤ 1. Sub deleteTables()
¤ 2. Dim cat As New ADOX.Catalog
¤ 3. Dim tbl As ADOX.Table
¤ 4.
¤ 5. cat.ActiveConnection = CurrentProject.Connection
¤ 6.
¤ 7. For Each tbl In cat.Tables
¤ 8. If tbl.Type = "TABLE" Then
¤ 9. cat.Tables.Delete tbl.Name
¤ 10. End If
¤ 11. Next
¤ 12.
¤ 13. Set tbl = Nothing: Set cat = Nothing
¤ 14. End Sub
¤ ------------------------------------------
¤ If I change the line 9. with
¤ DoCmd.DeleteObject acTable, tbl.Name
¤ the modified code deletes all tables. Why is it so?

ADOX operates a bit differently than Access or DAO. It's possible that it may be discriminating
between a TABLE and a VIEW. I would dump out all the table names and their corresponding types in
order to verify whether this is the case.


Paul
~~~~
Microsoft MVP (Visual Basic)
.



Relevant Pages

  • Re: VB6, VB2005, or Something Else?
    ... is associated with each record type when using a Select...Case statement. ... Exit Sub ... ¤ Nope, nothing complicated here. ... single Sub. ...
    (microsoft.public.vb.general.discussion)
  • Re: beginner update excel ?
    ... Private Sub Update_Click(ByVal sender As System.Object, ... ¤ fields and records must be specified. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: VB6, VB2005, or Something Else?
    ... ¤> language and it can be easily ... But if you're using several GoSubs in a Sub or Function then it's ... The ability to write bad code is not an excuse to use GoSub. ... I'd have to use a knife, but I would miss the screwdriver. ...
    (microsoft.public.vb.general.discussion)
  • Re: Sub Main() closes form on exit
    ... In VB6 we have adopted a common practice of starting applications from ... > ¤ Mainin a module. ... Within Sub Mainwe open any one of a number of ... presumably because the form object falls out of scope. ...
    (microsoft.public.vb.general.discussion)
  • Re: VB6, VB2005, or Something Else?
    ... ¤> interested. ... The ability to write bad code is not an excuse to use GoSub. ... Other langauges do support nested procedures and logically a nested ... If there is an advantage to using it in place of a Sub or Function ...
    (microsoft.public.vb.general.discussion)