Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3303728
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:59:15+00:00 2026-05-17T20:59:15+00:00

I’m wondering if it is possible to use VBA to store, delete and recreate

  • 0

I’m wondering if it is possible to use VBA to store, delete and recreate relationships on tables in Access VBA? The deletion part is easy, but how to store it in such a way as to be able to restore it after it’s been deleted is where I get stuck.

I originally wanted to know so that I could bulk copy certain tables from one database into another copy of that database. I ran into trouble as the ref. integrity on the tables was interfering with the inserts. I thought about trying to store then delete the relations, insert the data, then restore the relations using DAO.

After thinking about it and trying to come up with some code for it, I abandoned the idea and inserted it in a different way to avoid the issue altogether. However, after the fact, I was pondering if what I had been trying is doable.

Any thoughts?

EDIT: Here’s the code I started to write.

Private Sub Save_Click()
    Dim db As DAO.Database

    Set db = CurrentDb
    'Save db.Relations somehow as SavedRelations
End Sub

Private Sub Delete_Click()
    Dim db As DAO.Database
    Dim rel As DAO.Relation

    Set db = CurrentDb

    For Each rel In db.Relations
        db.Relations.Delete (rel.Name)
    Next
End Sub

Private Sub Restore_Click()
    Dim db As DAO.Database
    Dim rel As DAO.Relation
    Dim newRel As DAO.Relation

    For Each rel In SavedRelations 'Stored relations from the Save sub
        Set newRel = db.CreateRelation(rel.Name, rel.table, rel.ForeignTable, rel.Attributes)
        For Each fld In rel.Fields
            newRel.Fields.Append fld
        Next
        db.Relations.Append newRel
    Next
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:59:15+00:00Added an answer on May 17, 2026 at 8:59 pm

    If you make a backup copy of your database before you delete the relations, you can copy them back later.

    Private Sub Restore_Click()
        Dim db As DAO.Database
        Dim dbBackup As DAO.Database
        Dim rel As DAO.Relation
        Dim newRel As DAO.Relation
    
        Set db = CurrentDb()
        Set dbBackup = OpenDatabase("C:\temp\backup.mdb")
        For Each rel In dbBackup.Relations 
            Set newRel = db.CreateRelation(rel.Name, rel.table, rel.ForeignTable, _
                rel.Attributes)
            For Each fld In rel.Fields
                newRel.Fields.Append newRel.CreateField(fld.Name)
                newRel.Fields(fld.Name).ForeignName = _
                    rel.Fields(fld.Name).ForeignName
            Next fld
            db.Relations.Append newRel
        Next rel
        Set fld = Nothing
        Set rel = Nothing
        Set dbBackup = Nothing
        Set db = Nothing
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.