If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Copying Relationships from one mdb to an other
We have just found that after some damage to a users database (back-end)
some time back, a large number of relationships have disappeared. Many important tables are no longer related and referential integrity is no longer enforced. We have an old backup of the database for which the relationships are intact. Is anyone aware of some code we could use to delete the remaining relationships and then copy over the relationships from the old to the current database? Many thanks. -- Les Desser (The Reply-to address IS valid) |
#2
|
|||
|
|||
Copying Relationships from one mdb to an other
Hi Les
Are there really so many relationships that it's easier to write code than to add them manually? If so, then the following "air code" should get you started: Dim dbOld as Database, dbNew as Database Dim relOld as Relation, relNew as Relation Dim fldOld as Field, fldNew as Field Dim i as Integer Set dbNew = CurrentDb Set dbOld = OpenDatabase( "Path to backup db") ' delete old relations For i = dbNew.Relations.Count - 1 to 0 step -1 dbNew.Relations(i).Delete Next i ' add new relations For each relOld in dbOld.Relations Set relNew = dbNew.CreateRelation( relOld.Name, relOld.Table, _ relOld.ForeignName, relOld.Attributes ) For each fldOld in relOld.Fields Set fldNew = relNew.CreateField( fldOld.Name ) fldNew.ForeignName = fldOld.ForeignName relNew.Fields.Append fldNew Next fldOld dbNew.Relations.Append relNew Next relOld dbOld.Close As I said, this is "air code" - just typed into the newsreader, unchecked and untested. However, it should get you going on the right track. -- Good Luck :-) Graham Mandeno [Access MVP] Auckland, New Zealand "Les Desser" wrote in message ... We have just found that after some damage to a users database (back-end) some time back, a large number of relationships have disappeared. Many important tables are no longer related and referential integrity is no longer enforced. We have an old backup of the database for which the relationships are intact. Is anyone aware of some code we could use to delete the remaining relationships and then copy over the relationships from the old to the current database? Many thanks. -- Les Desser (The Reply-to address IS valid) |
#3
|
|||
|
|||
Copying Relationships from one mdb to an other
In article , Graham
Mandeno Wed, 2 Jul 2008 11:25:22 writes Are there really so many relationships that it's easier to write code than to add them manually? The documentation analyser produces 188 pages from the good file and 130 from the bad one. If so, then the following "air code" should get you started: Thank you - I will give it a try. Looks simple enough - when you know how Thanks again. -- Les Desser (The Reply-to address IS valid) |
Thread Tools | |
Display Modes | |
|
|