Results 1 to 3 of 3

Thread: Combo box control and MS Access

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 1999
    Posts
    2

    Post

    I was wondering if anyone could explain how to populate the list property of a combo box in VB6 when the combo box has been bound to a data control (MS Access). I can get the first record to populate, but as far as the list is concerned, I'm lost. I was thinking of using a Do/Until Loop until the EOF is reached, but I cannot get it to work properly. If someone can point me in the right direction, I would really appreciate it.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    I wouldn't use the standard Combobox/Listbox controls to bind to a Database, if you must bind a control, use the Databound List Controls in the Components list. Otherwise you could fill the Combobox yourself (Preferred Method):
    Code:
    Private Sub Form_Load()
        Dim oDb As Database
        Dim oRs As Recordset
        Set oDb = Workspaces(0).OpenDatabase("Nwind.mdb")
        Set oRs = oDb.OpenRecordset("SELECT FirstName FROM Employees", dbOpenForwardOnly)
        While Not oRs.EOF
            Combo1.AddItem oRs(0)
            oRs.MoveNext
        Wend
        If Combo1.ListCount Then Combo1.ListIndex = 0
        Set oRs = Nothing
        oDb.Close
        Set oDb = Nothing
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3
    New Member
    Join Date
    Jul 1999
    Posts
    7

    Post

    Hello;

    I haven't been able to achieve that with the "standard" list/combo box's. However,go to components and select the "Microsoft Data Bound List Controls", this will add DBListbox and DBCombobox on your menu. After you replace the list and/or combo box, you can then set the DataSource, Datafield, ListField, etc... to what you are wanting.
    When in doubt, press F1, it will guide you through it.

    Hope this helps

    --Steph

    ------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width