Steve F
Steve F

Reputation: 1587

Access listbox rowsource not updating via VBA

Using: MS-Access 2013; Windows 8.1 Professional

I am trying to update the displayed values in a ListBox in Access by setting the RowSource property in VBA to an SQL statement. However its not working. The listbox does not show the results of the SQL.

Here is my VBA code:

Private Sub cmbStudent_Change()
  Dim s As Integer

  s = cmbStudent & ""

  ' cmbTerm is a ListBox

  cmbTerm.RowSourceType = "Table/Query"

  cmbTerm.RowSource = "SELECT DISTINCT Terms.TermID, Terms.TermName " & _
                      " FROM Terms " & _
                      " ORDER BY Terms.TermCode;"

   cmbTerm.Requery


End Sub

After cmbTerm.Requery, the listbox is still empty ie. its not drawing the values from the TERMS table.

Without using a RecordSet (ADODB.RecordSet) object is there any way to make this work?

enter image description here

Thank you in advance for any helpful inputs.

Upvotes: 0

Views: 5024

Answers (1)

Mr Man
Mr Man

Reputation: 1

I have been having the same issue I had to fix it by putting this code at the end.

Me.Listbox.RowSourceType = "Value List"
Me.Listbox.RowSourceType = "Table/Query"

Note I had to also put it in a sub above the one that declared the RowSource.

so the RowSource is in a sub that is called by the main RowSource

Upvotes: 0

Related Questions