Solved

I am looking for code to import data from a MDB table to dropdown list combo (read from access and show the list in combo)

Posted on 2004-10-01
3
124 Views
Last Modified: 2010-05-02
Kindly suggest me a code that i can use to get data from an mdb table from a combo drop down list.
Read from access and show the list in combo.
0
Comment
Question by:gopinair
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 20 total points
ID: 12204125
This should do it.  You'll need to edit the code below and insert the name and location of your database, the name of the table you want to read from, and the name of the field you want to isnert into the combobox.

    'Include a reference to Microsoft ActiveX Data Objects 2.x Library
    Dim adoCon As New ADODB.Connection, _
        adoRS As New ADODB.Recordset
    adoCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\MyDb.Mdb;Persist Security Info=False"
    adoCon.CursorLocation = adUseServer
    adoCon.Open
    adoRS.Open "MyTable", adoCon, adOpenDynamic, adLockReadOnly, adCmdTableDirect
    While Not adoRS.EOF
        Combo1.AddItem adoRS.Fields("MyField")
        adoRS.MoveNext
    Wend
    adoRS.Close
    adoCon.Close
    Set adoRS = Nothing
    Set adoCon = Nothing
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12561325
Accept BlueDevilFan.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

744 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

11 Experts available now in Live!

Get 1:1 Help Now