ADOX relationship creation

James Deckert

Continuing to Learn
Local time
Today, 15:41
Joined
Oct 6, 2005
Messages
189
I am creating a 1 to many relationship between 2 tables (in the back end). I
want the record on the parent table to be optional (0 or 1 record). While
creating the relationship programmatically I get an error. "You cannot add or
change a record because a related record is required in table "Diamond Vender
POW" (the parent table). The parent table is currently empty and the child
table contains data.
Parent table = [Diamond Vender POW]
Child table = [Diamond All]
linking field in both tables =[Vender POW]

The following is the creation of the relationship, I am leaving out the
creation of the table and primary key of [Diamond Vender POW] as they work
fine. [Diamond All] is an existing table.

Set cat = New ADOX.Catalog
Dim keyNew As New ADOX.Key
On Error GoTo TableERR
With keyNew
.Name = "DiamondVenderPOWDiamondAll"
.Type = adKeyForeign
.RelatedTable = "Diamond Vender POW"
.Columns.Append "Vender POW"
.Columns("Vender POW").RelatedColumn = "Vender POW"
.UpdateRule = adRINone
.DeleteRule = adRINone
End With
'
' append the foreign key
cat.Tables("Diamond All").keys.Append keyNew

I can manually create the relationship in the back end and
everything works as I want. I added a form in the front end to display the
data and it works great.

I have another routine which does the same creation of a relationship but
the difference is that in this case I want the parent record to be optional.
In the other routine which creates the relationship fine, it is the child
table which is new.

The error msg leads me to believe that I am setting referential integrity. I intentionally turned off the updateRule and deleteRule, but if I omit these, I get the same error. I don't see an option to turn on/off basic referential integrity. Is RI assumed? How do I turn it off?

any ideas would be greatly appreciated.
thanks,
James
 

Users who are viewing this thread

Back
Top Bottom