Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Filling a list box with data from other database.

Posted on 2000-04-06
1
Medium Priority
?
171 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 200 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

876 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