Link to home
Start Free TrialLog in
Avatar of Paul Schuler
Paul SchulerFlag for United States of America

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.RowSourceType = "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.RowSourceType = "Table/Query"    
    Me.lstResultsByTrack.RowSource = strSQL
    Me.lstResultsByTrack.Requery
       
End Sub

Any suggestions appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Máté Farkas
Máté Farkas
Flag of Hungary image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
agree with Mate, no points please

It looks like you have a space between the ' and the " before the first & in you SQL Statement.
Avatar of Paul Schuler

ASKER

That was the issue thank you both very much for the assist!
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
Thanks again