I'm wanting to be able to select multiple items in a listbox and then filter a report by what is selected. I have the report's rowsource as a query, the criteria of the query points to a text box on my form. I have code that puts all the selected items in a string with each selected item separated by OR and then puts this string in that textbox. If I only select one item it will filter the report correctly, however with more than 1 selected it show a blank report. So it's not getting the criteria in the right format or something like that.
If I have 4 items selected this is an example of the string it would send to the textbox. '3R232' OR '3R235' OR '3R2PD.01' OR '3RA016' . The query has this in the criteria [Forms]![Filter Report Form]![AFENumber1] which points to the textbox on the form.
Here is the code for the on click of a command button:
Dim ctlSource As Control
Dim strItems As String
Dim intCurrentRow As Integer
Set ctlSource = Me!lstAFENumber
For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strItems = strItems & Chr(39) & ctlSource.Column(0, intCurrentRow) & Chr(39) & " OR "
End If
Next intCurrentRow
strItems = Left(strItems, Len(strItems) - 4) 'Remove the last " Or "
Me.AFENumber1 = strItems
I then open the report with an afterupdate event of a combo box which the user can select the name of the report to open. It doesn't work quite right. Is there anyway to do this with the current set up I have(e.g. with the underlying query of the report)?
Thanks,
Eric
If I have 4 items selected this is an example of the string it would send to the textbox. '3R232' OR '3R235' OR '3R2PD.01' OR '3RA016' . The query has this in the criteria [Forms]![Filter Report Form]![AFENumber1] which points to the textbox on the form.
Here is the code for the on click of a command button:
Dim ctlSource As Control
Dim strItems As String
Dim intCurrentRow As Integer
Set ctlSource = Me!lstAFENumber
For intCurrentRow = 0 To ctlSource.ListCount - 1
If ctlSource.Selected(intCurrentRow) Then
strItems = strItems & Chr(39) & ctlSource.Column(0, intCurrentRow) & Chr(39) & " OR "
End If
Next intCurrentRow
strItems = Left(strItems, Len(strItems) - 4) 'Remove the last " Or "
Me.AFENumber1 = strItems
I then open the report with an afterupdate event of a combo box which the user can select the name of the report to open. It doesn't work quite right. Is there anyway to do this with the current set up I have(e.g. with the underlying query of the report)?
Thanks,
Eric