Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to delete multiple tables on a command button.

Status
Not open for further replies.

Inky2201

Technical User
Jan 15, 2005
26
GB
Hello.
I am trying to delete all of the tables, on a command button, from a self contained database.
I have managed it with one table but for an unknown reason it does not want to delete all of the tables. I am using the code:

DoCmd.DeleteObject acTable, "TableName1"

This works but if I try to put this line in several times for other tables it will not work.
If I try to delete "TableName6" on its own it will not work.
I do not know the reason - I can only guess that it will delete table1 because that is the table that is being used and is therefore "live" at the time.
Any suggestions please?
Regards
I
 
What is the error it gives you? So long as the table isn't in use, you can delete it.

ChaZ

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
Hi Blorf,
I do not get any error message. It just does not carry out the function.
I
 
Do you have it saying on error resume next?

Do the tables have relationships set up? If so, that can cause you problems.

ChaZ

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
Yes Chaz,
You are right. The tables without the relationships are the ones that delete ok. Its the ones that have the relationships that do not. Will I have to give up on this?
I
 
If you know what the relationship are, I think you can delete them. The following comes from Access help. There may be other threads here also to provide more insight.

ChaZ

This example removes the foreign key from the Orders table.

Sub AlterTableX5()


Dim dbs As Database


' Modify this line to include the path to Northwind

' on your computer.

Set dbs = OpenDatabase("Northwind.mdb")


' Remove the OrdersRelationship foreign key from

' the Orders table.

dbs.Execute "ALTER TABLE Orders " _

& "DROP CONSTRAINT OrdersRelationship;"


dbs.Close


End Sub


There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top