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
129 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2005 text editor 10 54
Child Form in front 4 65
all the possible sequences for numbers 1,2,3,4,5,6,7,8,9,10 in groups of 5. 5 63
2 Global Vars, 1 List Box 4 31
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

734 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