UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> How To Delete Relationship In A Backend Table, Any Version    
 
   
fogline
post Mar 5 2018, 07:41 PM
Post#1



Posts: 33
Joined: 5-August 15
From: Ringgold, GA.


I had this working good but now when I run it it will delete ALL Relations in the BackEnd Database?
It should just Delete the Relationship between the 2 tables tblDrivers and tblDriverWithHolding
Can anyone see what I am doing wrong??



Function DeleteRelation()

Dim db As DAO.Database
Dim rel As Relation
Dim inti As Integer
Dim iAns As Integer
Dim Table1 As String
Dim Table2 As String

Table1 = "tblDrivers"
Table2 = "tblDriverWithHolding"

Set db = DBEngine(0)(0)

For inti = db.Relations.Count - 1 To 0 Step -1
Set rel = db.Relations(inti)
If (rel.Table = Table1 And rel.ForeignTable = Table2) _
Or (rel.Table = Table2 And rel.ForeignTable = Table1) _
Then


End If

db.Relations.Delete rel.Name

Next inti

End Function
Go to the top of the page
 
theDBguy
post Mar 5 2018, 08:41 PM
Post#2


Access Wiki and Forums Moderator
Posts: 72,377
Joined: 19-June 07
From: SunnySandyEggo


Hi,

Just a guess but try moving the "delete" command inside the If/Then block. For example:

If (...) Or (...) Then

db.Relations.Delete rel.Name

End If

Hope it helps...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 
fogline
post Mar 5 2018, 08:54 PM
Post#3



Posts: 33
Joined: 5-August 15
From: Ringgold, GA.


Wow you saved the day again DBguy.
That worked.
I wish you had a donate button on here or your website.
Go to the top of the page
 
theDBguy
post Mar 5 2018, 09:15 PM
Post#4


Access Wiki and Forums Moderator
Posts: 72,377
Joined: 19-June 07
From: SunnySandyEggo


Hi,

You're very welcome. Glad we could assist.

A donate button sounds like a good idea. UA has one on the main menu above.

If you insist on buying me a cup of coffee, you can use the following link for now:

https://paypal.me/thedbguy

Thanks.

Good luck with your project.

Cheers! cheers.gif

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Microsoft Access MVP | Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    19th June 2018 - 03:49 AM