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

  • SEARCH
  • Home
  • 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 8627541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:18:23+00:00 2026-06-12T08:18:23+00:00

I am trying to create an Access database that will link together multiple structurally

  • 0

I am trying to create an Access database that will link together multiple structurally identical databases together. These other databases are exports from a 3D model that have identical tables, but different data in each. What I need to do is report from all the database like they are one big database. How I thought I would approach this is to create queries that would union the individual identical tables from each database into one query, which I could then use in all my other reports. the code I wrote to join the tables together is below. The trouble I’m running into is that , this code gives me an out of stack space error on the “Set QueryDef…” line. Can someone tell me what I’m doing wrong?

Public Sub CreateUnionQueries()
'On Error GoTo Err_CreateUnionQueries
Dim QueryRs As DAO.Recordset
Dim TableRs As DAO.Recordset
Dim QueryDef As DAO.QueryDef
Dim SQLText As String
Dim qry As QueryDef

'Get list of all Foreign Table Names
Set QueryRs = CurrentDb.OpenRecordset("select distinct ForeignName from msysobjects where ForeignName is not null")

'Loop over list to create union queries
If QueryRs.RecordCount <> 0 Then
    Do While Not QueryRs.EOF
        Set TableRs = CurrentDb.OpenRecordset("select Name from msysobjects where ForeignName = """ & QueryRs![ForeignName] & """")
        Do While Not TableRs.EOF
            SQLText = SQLText & "select * from " & TableRs![Name]
            TableRs.MoveNext
            If Not TableRs.EOF Then
                SQLText = SQLText & " UNION ALL "
            End If
        Loop
        'Create union query
        For Each qry In CurrentDb.QueryDefs
            If qry.Name = "Q-" & QueryRs![ForeignName] Then
               DoCmd.DeleteObject acQuery, "Q-" & QueryRs![ForeignName]
            End If
        Next qry
        Set QueryDef = CurrentDb.CreateQueryDef("Q-" & QueryRs![ForeignName], SQLText)
        QueryDef.Close
        Set QueryDef = Nothing
        QueryRs.MoveNext
        TableRs.Close
        Set TableRs = Nothing
    Loop
Else
    MsgBox "No files are linked currently"
End If

QueryRs.Close

Err_CreateUnionQueries:
    MsgBox "We have an error"
    Set QueryRs = Nothing
    Set TableRs = Nothing
    Exit Sub
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-06-12T08:18:24+00:00Added an answer on June 12, 2026 at 8:18 am

    Oh man, I’m an idiot. Found the problem. When I was looping, I wasn’t setting SQLText back to empty, so it was appending my query for table group onto the last. Removed that and now it works as expected. Thank you guys for your help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a function that will block access to some of
I'm trying to create a simple web bot which will access a certain page,
I am trying to create a class with various methods that will need to
I am trying to create a macro that will regularly move 25,000 - 35,000
I am trying to create a SQL statement that will allow me to remove
I'm trying to have a trigger set up in an arbitrary database that will
I am trying to make a report to go with my access database that
I'm trying to create a database that contains a list of equipment. All of
I am trying to create a booking system in C#.NET that will store bookings
I am currently trying to improve on an Access Database VBA that I have

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.