Code for delete Table from other Database file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Dim dbOther As DAO.Database

Set dbOther = OpenDatabase("Full path to database")
dbOther.TableDefs.Delete "Name of Table to delete"
Set dbOther = Nothing
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top