Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can relationships be created with code?

Status
Not open for further replies.

PurpleUnicorn

Programmer
Mar 16, 2001
79
US
I have a table, with a 5 field primary key, that is related to 5 other tables. Every so often, for no explainable reason, an update to the primary table (via a form) causes the record in the primary table to become corrupt and ultimately requires its demise by deletion. This in turn causes Access XP to drop all of the relationships on the primary table.

Is there a quick way to rebuild the relationships using code? Also, if anyone has any idea why the problem may occur in the first place, I would love to hear.

Thanks!
 
It can be done, but it would be better to use an error log to trap the errors as they occur, instead of dealing with the symptoms.

Having said that:

Set relDest = dbsDest.CreateRelation(relSource.Name, relSource.Table, relSource

Set fldDest = relDest.CreateField(FieldName)
fldDest.ForeignName = ForeignName
relDest.Fields.Append fldDest

dbsDest.Relations.Append relDest
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top