Good evening loungers
I am attempting to delete and then recreate a realtionship.
This code pretty much is flogged from Access help.
Code is falling over at appending the newly recreated relationship.
Error msg states that object cannot be found.
Any assistance greatly appreciated.
Merry christmas
Geof
>>>>>>>>>>>>
Sub relationsTest()
Dim db As Database
Dim rel As Relation
Dim fld As Field
Set db = CurrentDb
For Each rel In db.Relations
If rel.Table = “tblSiteAssessments” And rel.ForeignTable = “tblFaunaFlora” Then
db.Relations.Delete rel.Name
Exit For
End If
Next rel
‘ Create new relationship and set its properties.
Set rel = db.CreateRelation(“tblSiteAssessments”, “tblFaunaFlora”)
‘ Set Relation object attributes to enforce referential integrity.
rel.Attributes = dbRelationDeleteCascade
‘ Create field in Fields collection of Relation object.
Set fld = rel.CreateField(“SurveyNumber”)
‘ Provide name of foreign key field.
fld.ForeignName = “SurveyNumber”
‘ Append field to Relation object and Relation object to database.
rel.Fields.Append fld
db.Relations.Append rel
MsgBox “Relation ‘” & rel.Name & “‘ created.”
Debug.Print “Attributes of relations in ” & db.Name & “:”
For Each rel In db.Relations
Debug.Print ” ” & rel.Name & ” = ” & rel.Attributes
Next rel
db.Close
Set db = Nothing
End Sub
>>>>>>