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 8796655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:40:23+00:00 2026-06-13T23:40:23+00:00

I have actually this little function working as supposed: Function createAttached(strTable As String, strPath

  • 0

I have actually this little function working as supposed:

Function createAttached(strTable As String, strPath As String, strBaseTable As String) As Boolean
    On Error GoTo CreateAttachedError

    Dim tdf As TableDef
    Dim strConnect As String
    Dim fRetval As Boolean
    Dim myDB As Database

    DoCmd.SetWarnings False

    Set myDB = CurrentDb
    Set tdf = myDB.CreateTableDef(strTable)

    With tdf
        .Connect = ";DATABASE=" & strPath
        .SourceTableName = strBaseTable
    End With

    myDB.TableDefs.Append tdf
    myDB.TableDefs.Refresh

    fRetval = True

    DoCmd.SetWarnings True

CreateAttachedExit:
    createAttached = fRetval
    Exit Function

CreateAttachedError:
    If Err = 3110 Then
        Resume CreateAttachedExit
    Else
        If Err = 3011 Then
            Resume Next
        Else
            If Err = 3012 Then
                Set tdf = myDB.TableDefs(strTable)
                tdf.Connect = ";DATABASE=" & strPath
                tdf.RefreshLink
                fRetval = True
                GoTo CreateAttachedExit
            End If
        End If
    End If
End Function

This code works fine, I can call the function as many times as I want to add links to tables from another database. However, I have about 30 tables to import from the same database and this script restarts from scratch everytime I call it. Because the database is located on another server, it takes about 1 min to link the 30 tables.

Is there anything I could do with that function to make it work faster when I need to link multiple tables from the same database? I would like it to work with multiple strTable and strBaseTable in parameters instead of one (maybe arrays?), but I don’t know how to do this.

Thank you.

  • 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-13T23:40:24+00:00Added an answer on June 13, 2026 at 11:40 pm

    You can loop through the tabledefs collection in the external database or use a table of tables that lists all the tables to be connected and the external database.

    Dim db As Database
    Dim ThisDb As Database
    
    Set ThisDb = CurrentDB
    sDb = "z:\docs\test.accdb"
    Set db = OpenDatabase(sDb)
    
    For Each tdf In db.TableDefs
        ''Connect
        If Left(tdf.Name, 4) <> "MSys" Then
            If IsNull(DlookUp("Name","MsysObjects","Type In (1,4,5,6) And Name='" _
               & tdf.Name & "'")) Then
               DoCmd.TransferDatabase acLink, "Microsoft Access", _
                 sDb, acTable, tdf.Name, tdf.Name
            Else
              If ThisDb.TableDefs(tdf.Name).connect <> vbNullString Then
                 ThisDb.TableDefs(tdf.Name).connect = ";DATABASE=" & sDb
                 ThisDb.TableDefs(tdf.Name).RefreshLink
              End If
            End If
        End If
    Next
    

    A table of tables would work in a similar fashion in that you can select the database (select distinct) from the table and loop through that recordset attaching the tables in a further selection (select table where database …)

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

Sidebar

Related Questions

Since the advent of AS3 I have been working like this: private var loggy:String;
I have an awesome little function that looks like this: def verbose_print(message, *args, **kwargs):
i have a very simple question, actually this is not the question, this is
Actually I have this list Directory where I am adding the name of the
I have seen code like this (actually seeing another person type it up): catch
I am finally asking this question as I have never actually found an answer.
This is a minimal test case of some code that I actually have. It
I have a Wifi iPad and this compass actually knows the direction of north.
Actually I have some MVC3 Applications and I want to call this applications from
What does this mean: Next add reference to: MySql.Data actually I have downloaded mysql

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.