• Populate Listbox (VB6)

    Author
    Topic
    #363087

    I just spent the better half of the day trying to just populate a listbox using an ADO connection to an Access 97 database.

    I figured out that you can’t just assign the RS object to the Datasource property of the listbox and expect it to populate automatically. I finally set up a loop using the AddItems Method to insert them one by one. I’m finding that it is inserting them all in one row. I verified that I do have Columns set to 2.

    Here is the code. This is all being done in the load event of the form:

    Dim rs As New ADODB.Recordset

    Dim cn As New ADODB.Connection

    cn.Open “Provider=Microsoft.jet.oledb.3.51;” _
    & “Data Source=C:DatabaseOncology.mdb”

    rs.Source = “SELECT DISTINCT tblPath.MRNumber, tblPath.Seq, tblPath.Path FROM tblPath”

    Set rs.ActiveConnection = cn

    rs.Open , cn

    With lstRM
    Do While Not rs.EOF

    .AddItem rs(1) & rs(2)

    rs.MoveNext

    Loop
    End With

    ‘Set lstRM.DataSource = rs

    Viewing 0 reply threads
    Author
    Replies
    • #553080

      Mike,
      Unfortunately, the listbox columns in VB are not like the listbox columns in Access. If you stretch the height of your listbox to accomodate more rows you will see somewhat different results, but not what you want. As you’ve discovered, the listbox with columns scrolls horizontally, not vertically. If the data in your tables is all the same width you might try setting columns back to 0, and putting tabs between the fields:
      listbox.additem rs(1) & vbTab & rs(2)

      • #553315

        Thanks, Dottie. It is all making sense now.

        I switched to the Listview control which seems to be a lot more friendly

    Viewing 0 reply threads
    Reply To: Populate Listbox (VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: