Solved

Filling a list box with data from other database.

Posted on 2000-04-06
1
162 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
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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.

860 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