Deleting a table relationship in VBA (1 Viewer)

Design by Sue

Registered User.
Local time
Yesterday, 22:32
Joined
Jul 16, 2010
Messages
648
Can someone help me with this please. I have an existing database and need to add a primary key to one of the tables. I can't do this because there are one to many relationships from that table so I need to remove the existing relationships before I make the primary key and then put the relationships back. I can do the primary key and adding the relationships but can't find the way to deleted relationships. My searching came up with deleting ALL relationships in a database and I definitely do not want to do that! I can find plenty on how to add relationships but I can do that. Can someone please help me with the code for the delete part only??

Thanks
Sue
 

robslob

Registered User.
Local time
Today, 06:32
Joined
Apr 26, 2015
Messages
27
I ploughed through a couple of ebooks and the nearest thing to deleting a relationship was this bit of code

'Check if the relationship already exists.
'If so, delete it.
If IsObject(dbs.Relations(strRelName)) Then
dbs.Relations.Delete strRelName
End If

I havn't practiced any of this stuff though so I can't really add anymore than that.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:32
Joined
Sep 12, 2006
Messages
15,658
why would you need to delete the relationships to add an extra key to a table? and why a primary key at this stage?

but anyway - surely just open the relationships pane, select the affected tables/links, right-click and delete them. I wouldn't try and do something like this in code. Surely this is a design thing, not a run-time thing.

Am I missing something?
 

Users who are viewing this thread

Top Bottom