vbat-sqlms-accesslistboxrecordset

Populate a listbox in a form with recordset using MS Access VBA


I'm trying to populate a listbox in a form using VBA in MS Access.

The listbox does not get populated.

Private Sub Form_Load()
    linkedOrders = linkedOrderList

    qGetLinks = "SELECT *Various fields from table* FROM *Table* WHERE *Conditioned_field* IN(" & linkedOrders & ")"
    Set rsLinks = CurrentDb.OpenRecordset(qGetLinks, dbOpenDynaset, dbSeeChanges)

    Me.selListRS.RowSourceType = "Query/Table"
    Me.selListRS.RowSource = ""

    Set Me.selListRS.Recordset = rsLinks
End Sub

linkedOrderList is a global variable that is populated correctly upon loading the form.

I ran the code using breakpoints to make sure that all variables and recordsets get populated.

The recordset rsLinks gets the expected result from my SQL-query.
I also checked my spellings a few times.


Solution

  • This is wrong:

    Me.selListRS.RowSourceType = "Query/Table"
    

    Edit it as following:

    Me.selListRS.RowSourceType = "Table/Query"