Solved

Filling a list box with data from other database.

Posted on 2000-04-06
1
164 Views
Last Modified: 2011-09-20
I've got a database that has a form that needs to display the results of a query against another access database.  Currently I do this by opening the other database running the query and then copy the results into the rowsource property of the list box, after clicking values.  This works, however lately the query result got bigger and rowsource is limited to 2,000 characters.  
What is the proper way of doing this?  I'm assuming I'll need to link the foreign table but since the other database is user's choice I'll need to do this in code.  Also I'll need to delete the link later.
0
Comment
Question by:calvinrsmith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
MikeRenz earned 50 total points
ID: 2692264
Here is some code for linking all tables from a specified database (mypath = the path to the database) and also for deleting the links to those tables.  You can modify it to only link in certain tables by ripping out the loops and exchanging tdf.name with the name of the table you want to link in.

After you have your link then just join the two tables being compared in a query...joining on the similar ids or whatever you are trying to accomplish.


Private Sub DeleteAttachedTables(MyPath as string)
Dim MyDatabase As Database
Dim tdf As TableDef
Dim ReturnValue As Integer

    Set MyDatabase = DBEngine.OpenDatabase(MyPath) ' Open database.
    For Each tdf In MyDatabase.TableDefs
        If tdf.Attributes And dbSystemObject Then
        Else
            ReturnValue = SysCmd(SYSCMD_SETSTATUS, "Deleting Table " & tdf.name)
            DoCmd.DeleteObject acTable, tdf.name
        End If
    Next

    ReturnValue = SysCmd(SYSCMD_REMOVEMETER)

End Sub

Private Sub ReAttachTable(MyPath As String)
Dim MyDatabase As Database
Dim tdf As TableDef
Dim ReturnValue As Integer

    Set MyDatabase = DBEngine.OpenDatabase(MyPath) ' Open database.
    For Each tdf In MyDatabase.TableDefs
        If tdf.Attributes And dbSystemObject Then
        Else
            ReturnValue = SysCmd(SYSCMD_SETSTATUS, "Attaching Table " & tdf.name)
            DoCmd.TransferDatabase acLink, "Microsoft Access", MyPath, acTable, tdf.name, tdf.name
        End If
    Next

    ReturnValue = SysCmd(SYSCMD_REMOVEMETER)

End Sub
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question