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
126 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

785 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