Reputation: 1587
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?
Thank you in advance for any helpful inputs.
Upvotes: 0
Views: 5024
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