Paul Schuler
asked on
MS Access 2016 How top populate a list box from a combobox selection using command button
Hello,
I have a form with a combo box that gets populated on form load. I want the user to be able to select a value in the combo box, click on a command button with sql that should populate the rowsource of the list box with the results. Not getting any results in the list box. Code:
Private Sub Form_Load()
Me.cboTrackName.RowSourceT ype = "Table/Query"
Me.cboTrackName.RowSource = "SELECT DISTINCT dbo_wagers.track" & _
" FROM dbo_wagers WHERE dbo_wagers.track Is Not Null ORDER BY dbo_wagers.track;"
Me.cboTrackName = Me.cboTrackName.ItemData(0 )
End Sub
Private Sub cmdFilteredResults_Click()
Dim strSQL As String
strSQL = "select dbo_wagers.wager from dbo_wagers where dbo_wagers.track = ' " & Me.cboTrackName.Value & "'"
MsgBox "Current track selected is " & Me.cboTrackName.Value & ""
MsgBox "Query is " & strSQL & ""
Me.lstResultsByTrack.RowSo urceType = "Table/Query"
Me.lstResultsByTrack.RowSo urce = strSQL
Me.lstResultsByTrack.Reque ry
End Sub
Any suggestions appreciated.
I have a form with a combo box that gets populated on form load. I want the user to be able to select a value in the combo box, click on a command button with sql that should populate the rowsource of the list box with the results. Not getting any results in the list box. Code:
Private Sub Form_Load()
Me.cboTrackName.RowSourceT
Me.cboTrackName.RowSource = "SELECT DISTINCT dbo_wagers.track" & _
" FROM dbo_wagers WHERE dbo_wagers.track Is Not Null ORDER BY dbo_wagers.track;"
Me.cboTrackName = Me.cboTrackName.ItemData(0
End Sub
Private Sub cmdFilteredResults_Click()
Dim strSQL As String
strSQL = "select dbo_wagers.wager from dbo_wagers where dbo_wagers.track = ' " & Me.cboTrackName.Value & "'"
MsgBox "Current track selected is " & Me.cboTrackName.Value & ""
MsgBox "Query is " & strSQL & ""
Me.lstResultsByTrack.RowSo
Me.lstResultsByTrack.RowSo
Me.lstResultsByTrack.Reque
End Sub
Any suggestions appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was the issue thank you both very much for the assist!
ASKER
That was the issue thanks for the assist!
Paul,
Mate provide the answer first, I was just endorsing his comment and requested no points. Recommend you request assistance on your original question and ask the moderators to reopen the question, so that you can reallocate points.
Dale
Mate provide the answer first, I was just endorsing his comment and requested no points. Recommend you request assistance on your original question and ask the moderators to reopen the question, so that you can reallocate points.
Dale
ASKER
Thanks again
It looks like you have a space between the ' and the " before the first & in you SQL Statement.