Deleting Relationships in VBA (1 Viewer)

Dudley

Registered User.
Local time
Today, 03:16
Joined
Apr 7, 2004
Messages
147
Hi,
I'm trying to delete tables using:

Code:
DoCmd.DeleteObject acTable, "table name"

but I'm getting an error message about the table's relationships. I've gone in and determined the names of the relationships, but can't successfully delete them. There isn't an "acRelation" constant, "acDefault" doesn't work (with the name of the relation in the next argument), so I'm stumped.

Can anyone help?? Thanks in advance!!!
 

Moniker

VBA Pro
Local time
Today, 05:16
Joined
Dec 21, 2006
Messages
1,567
If you have referential integrity/cascading changes on, you can't take a table out of the middle of a relationship train as that breaks all the referential integrity. You'd have to manually remove that table from the relationship first, or turn off referential integrity.
 

Dudley

Registered User.
Local time
Today, 03:16
Joined
Apr 7, 2004
Messages
147
Hmm. Thanks Moniker. There isn't a "force delete" argument I can use somewhere? Some way to code "Yes" to the "delete the relationships?" msgbox?
 

Moniker

VBA Pro
Local time
Today, 05:16
Joined
Dec 21, 2006
Messages
1,567
Look at Tools -> Relationships and see if the table is in there. If it is, you can remove the table from there and then you should be able to delete it without an issue.
 

Dudley

Registered User.
Local time
Today, 03:16
Joined
Apr 7, 2004
Messages
147
Thanks Moniker. The problem is that I'm trying to do this from code. I'm working on a snippet of code to "refresh" the database by deleting the data and lookup tables before using CopyObject to create new versions of the tables from structural templates I made. Once the data tables have been 'refreshed' this way, an Import process occurs, followed by re-creating the table relationships. I was just trying to make a button to reset the system for myself. Thanks!
 

Users who are viewing this thread

Top Bottom