A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Copying Relationships from one mdb to an other



 
 
Thread Tools Display Modes
  #1  
Old July 1st, 2008, 11:39 PM posted to microsoft.public.access.forms
Les Desser
external usenet poster
 
Posts: 45
Default 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  
Old July 2nd, 2008, 12:25 AM posted to microsoft.public.access.forms
Graham Mandeno
external usenet poster
 
Posts: 593
Default 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  
Old July 2nd, 2008, 12:45 PM posted to microsoft.public.access.forms
Les Desser
external usenet poster
 
Posts: 45
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.