MultiList Box as Parameter Query

  • Thread starter Thread starter taf
  • Start date Start date
T

taf

I am trying to use a MultiList Box instead of a combobox in order to
pass the variables through a query to generate a report. I think I
have the code right, but when I run, it gives me a syntax error re: the
query. How should the query be formatted? I still have the
[Forms]![MyForm]![MyListBox] in the criteria section --does that need
to change to something else?

Any help would be GREATLY appreciated!!!
 
Thanks, Brian. Could you tell me what the Me in the code refers to
(line 14)? That's throwing me off...

Private Sub cmdPreview_Click()
On Error GoTo Err_Handler
'Purpose: Open the report filtered to the items selected in the
list box.
'Author: Allen J Browne, 2004. http://allenbrowne.com
Dim varItem As Variant 'Selected items
Dim strWhere As String 'String to use as WhereCondition
Dim strDescrip As String 'Description of WhereCondition
Dim lngLen As Long 'Length of string
Dim strDelim As String 'Delimiter for this field type.
Dim strDoc As String 'Name of report to open.

'strDelim = """" 'Delimiter appropriate to field type.
See note 1.
strDoc = "Products by Category"

'Loop through the ItemsSelected in the list box.
With Me.lstCategory
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter from the bound column (hidden).
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text in the visible
column. See note 2.
strDescrip = strDescrip & """" & .Column(1, varItem) &
""", "
End If
Next
End With
 
taf,

'Me' is essentially a shorthand reference to your form within it's coding
module.

Brian
 
Back
Top