Delete Table

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

Guest

quick question, does anyone know how to delete a whole table, not just the
data, through vba?
 
Try:

Public Sub dropTbl()

On Error GoTo ErrHandler

CurrentDb().Execute "DROP TABLE tblTrash;", _
dbFailOnError

Exit Sub

ErrHandler:

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

End Sub

.. . . where tblTrash is the name of the table to get rid of. Very quick and
no special libraries are needed.

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.
 
This looks good, but how does it execute? Like, if I want to have it execute
when a button is clicked. Is there any benefit to doing this instead of the
simpler looking answer offered above (DoCmd.DeleteObject acTable,
"TableName")?
 
Ray,

I use the deleteobject myself, but embed it in a public sub like this:

public sub Delete_Object (TableName as string, TableType as byte)
on error resume next
docmd.setwarnings false
docmd.deleteobject Tabletpye, TableName
docmd.setwarnings true
end sub

This could be called from a command button's onClick event, or from any
VBA code. This may delete tables, querys, forms, etc


HTH,
Andy
 
i'm really curious too about the differences between the db vs do.cmd methods.

Thanks--
 
Back
Top