Solved

Filling a list box with data from other database.

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now