Applecore Pages on Microsoft Access

Deleting objects in another database

If you want to delete an object in a second database (for example, you are exporting a new version of the object into this database), then you have several options:

Sub sDeleteExternal1()
    Dim objAccess As New Access.Application
    With objAccess
        .OpenCurrentDatabase "C:\Whatever.mdb"
        .DoCmdDeleteObject acTable, "tblName"
        .CloseCurrentDatabase
    End With
End Sub

You might also wish to trap for errors, such as the object not existing in the second database.

Another option is to use the SQL statement, DROP, for tables:

Sub sDeleteExternal2()
    Dim db As Database
    Set db=OpenDatabase("C:\Whatever.mdb")
    db.Execute "DROP TABLE [tblName];"
    db.Close
    Set db=Nothing
End Sub

Or, you can delete the Tabledef Object:

Sub sDeleteExternal3()
    Dim db As Database
    Set db=OpenDatabase("C:\Whatever.mdb")
    db.TableDefs.Delete "tblName"
    db.Close
    Set db=Nothing
End Sub

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 14:55:20