Code for delete Table from other Database file

K

KK Chan

How can I write the code for a button to delete a Table from other Access
file. For example, click the button in file DB1 to delete a Table in file
DB2. Thanks
 
D

Douglas J. Steele

Dim dbOther As DAO.Database

Set dbOther = OpenDatabase("Full path to database")
dbOther.TableDefs.Delete "Name of Table to delete"
Set dbOther = Nothing
 
6

'69 Camaro

Hi.

Another way is to use DROP TABLE:

Private Sub DropTblBtn_Click()

On Error GoTo ErrHandler

CurrentDb().Execute "DROP TABLE [;DATABASE=C:\DB2.mdb;].tblTest;", _
dbFailOnError

Exit Sub

ErrHandler:

MsgBox "Error in DropTblBtn_Click( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Top