MS Access Help: Copying database Relationships

  • Thread starter Thread starter news.giganews.com
  • Start date Start date
N

news.giganews.com

Does anyone know if there's an easy way to export or copy the relationship
structure from one mdb to a new one? The relationships in the db are time
consuming to reproduce. I am trying to make a copy of a database including
all the relationships, forms, queries and modules while still within the
original database. This has to be a relatively automated process (button
click). Any suggestions?
 
got to your new database.
Select get external data
Select import
click the advanced box
Select relationships
then ok

eric
 
Sorry i did not realize you are in the database. I only know how to do it
from code. You could put this behind a command button

Private Sub Command10_Click()
Dim fso As Object
Dim boverwrite As Boolean
Dim fso As New Scripting.FileSystemObject
Set fso = CreateObject("Scripting.fileSystemObject")
fso.copyfile "sourcedb", "destinationdb"

Set fso = Nothing

End Sub

Before you can use the FileSystemObject you must set a reference to the
Windows scripting host.
 
There is a link on the following page, which creates a form to unreplicate a
database. Although that's not what you want to do, the code behind the form
will show you how to copy the relationships.

http://www.pacificdb.com.au/MVP/Code/UnReplicate.htm

But an easier way is to create a new database, and simply copy the tables
and relationships in one go.
1. Create the new database.
2. In the new database, display the Tables tab.
3. Select New, click Import Table, then click OK.
4. Select the database to copy from, then click Import.
5. Select all the tables you want to copy.
6. Click Options.
7. Make sure the Import Relationships checkbox is ticked.
8. Click OK.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 
Hello,

I have an additional question: the Import Relationships option makes sure
that the table relationships (foreign keys, referential integrity
definitions etc) are copied. There is also a visualisation of the
relationships through the
"Relationships" window (accessible via Tools => Relationships). After
copying tables and relationships from another database, the *layout* of the
Relationships is not copied, instead it shows all tables with all
relationships in a sequential order.

Does anyone know a way to also copy the *layout* of the relationships?

Thanks,
Vincent
 
Vincent,

When you create your own relationships in code, they will not automatically
appear in the Relationships window. To display the Relationships window,
display the Database window, then select Relationships from the Tools menu.
To display the new relationships you've created in code, you either add the
related tables to the Relationships window, or click Show All from the
Relationships menu. As for layout, I don't think that is accessible.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 
Back
Top