modifying code for multi select list box

F

Fipp

I have the following code that opens a report. In this code opponent is a
multi select list box. I am trying to change the code so that season can be a
multi select list box as well.

Here is the old code.

Private Sub hitchartrpt_Click()
DoCmd.OpenReport "hitchartrpt", acViewPreview, , _
"opponent in (" & Me.opponentselected & ") AND " & _
"season = " & Me.cboseason & " AND " & _
"team = '" & Me.cboteam & "'"
End Sub

Any help is appreciated.
 
O

Ofer Cohen

Try something like

Private Sub hitchartrpt_Click()
Dim I, strIN As String, strWhere As string

For i = 0 To opponentselected.ListCount - 1
If opponentselected.Selected(i) Then
strIN = strIN & opponentselected.Column(0, i) & ","
End If
Next i

'Create the WHERE string, and strip off the last comma of the IN string
strWhere = " "opponent in " & _
"(" & Left(strIN, Len(strIN) - 1) & ") And season = " &
Me.cboseason & " AND " & _
"team = '" & Me.cboteam & "'""

DoCmd.OpenReport "hitchartrpt", acViewPreview, , strWhere

End Sub

Note: I didn't try the code so it might need few modifications
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top