Click to See Complete Forum and Search --> : Delete table in Access Database


regis
November 30th, 1999, 12:58 PM
How can I delete table in Access Database?

I try with this:

Dim dbsNew As Database
Dim wrkDefault As Workspace
Dim td As TableDef
Set dbsNew = OpenConnection("c:\Windows\Temp\MarteleurVirtuel.mdb")

Set wrkDefault = DBEngine.Workspaces(0)
td.Name = "Position ha"
dbsNew.TableDefs.Delete td

But it was not a success. I recive an error at the last line: ("Type mismatch")


Has anyone can help me?
Thanks!

Redg

Michael Nattfalk
November 30th, 1999, 02:13 PM
Hi.

When you're going to delete a table you don't need to declare a TableDef object.

Do like this:
dbsNew.TableDefs.Delete "Position ha"



/Michael Nattfalk

Allen Noakes
November 30th, 1999, 02:28 PM
Redg,

Try this code instead and change the what you need to change.

Dim dbsNew As Database
Dim td As TableDef

Set dbsNew = OpenDatabase("d:\vbhelp\tbldel\db3.mdb")
dbsNew.TableDefs.Delete "Table1"


Allen Noakes
VB Programmer/Analyst
Dames & Moore Group
misan@dames.com

santulan
November 30th, 1999, 09:39 PM
Hi,
use the following.

dim codegurudb as database
dim mysql as string
set codegurudb = workspaces(0).opendatabase(app.path & "\test.mdb")
'say table name is xxx
mysql = "DROP TABLE xxx"
codegurudb.execute mysql
codegurudb.close



I assume that in project reference you add the DAO.


Santulan