G
Gabby Girl
Good Morning,
I have two multiple select list boxes that are used to filter a form. When
I try them seperately they work fine (comment out code for one & test the
other). But as soon as I try to make them both work together I get: Error
3075. Syntax Error (missing operator) in query expression '[ModelNbr] IN
([ManufacturesMake] IN ("Ford")"F150","F250")'.
I'm using code from Allen Browne (Use a Multi-select list box to filter a
report) and then adapted (obviously not very well) to my situation. I'm
assuming it's a missing bracket, but can't for the life of me figure out
where in the code it's missing. Could someone please look at my code a
enlighten me as to what I'm missing. (I've been working on this for 3 days
and have gone from blonde to bald trying to figure this out.
Code:
************************************
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 = "frmCARReportResults"
'Loop through the ItemsSelected in the list box.
With Me.lstManufacturesMake
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
'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[ManufacturesMake] IN (" & Left$(strWhere, lngLen) &
")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "tblEquipmentMaster.ManufacturesMake: " &
Left$(strDescrip, lngLen)
End If
With Me.lstModelNbr
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim &
","
strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
End If
Next
End With
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[ModelNbr] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "tblEquipmentMaster.ModelNbr: " & Left$(strDescrip,
lngLen)
End If
'Report will not filter if open, so close it. For Access 97, see note 3.
'If CurrentProject.AllReports(strDoc).IsLoaded Then
'DoCmd.Close acReport, strDoc
'End If
'Omit the last argument for Access 2000 and earlier. See note 4.
DoCmd.OpenForm strDoc, acNormal, WhereCondition:=strWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler
End If
End If
End Sub
**************************
I appreciate any help that anyone can give me.
Thanks Kindly
I have two multiple select list boxes that are used to filter a form. When
I try them seperately they work fine (comment out code for one & test the
other). But as soon as I try to make them both work together I get: Error
3075. Syntax Error (missing operator) in query expression '[ModelNbr] IN
([ManufacturesMake] IN ("Ford")"F150","F250")'.
I'm using code from Allen Browne (Use a Multi-select list box to filter a
report) and then adapted (obviously not very well) to my situation. I'm
assuming it's a missing bracket, but can't for the life of me figure out
where in the code it's missing. Could someone please look at my code a
enlighten me as to what I'm missing. (I've been working on this for 3 days
and have gone from blonde to bald trying to figure this out.
Code:
************************************
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 = "frmCARReportResults"
'Loop through the ItemsSelected in the list box.
With Me.lstManufacturesMake
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
'Remove trailing comma. Add field name, IN operator, and brackets.
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[ManufacturesMake] IN (" & Left$(strWhere, lngLen) &
")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "tblEquipmentMaster.ManufacturesMake: " &
Left$(strDescrip, lngLen)
End If
With Me.lstModelNbr
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim &
","
strDescrip = strDescrip & """" & .Column(1, varItem) & """, "
End If
Next
End With
lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[ModelNbr] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "tblEquipmentMaster.ModelNbr: " & Left$(strDescrip,
lngLen)
End If
'Report will not filter if open, so close it. For Access 97, see note 3.
'If CurrentProject.AllReports(strDoc).IsLoaded Then
'DoCmd.Close acReport, strDoc
'End If
'Omit the last argument for Access 2000 and earlier. See note 4.
DoCmd.OpenForm strDoc, acNormal, WhereCondition:=strWhere
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler
End If
End If
End Sub
**************************
I appreciate any help that anyone can give me.
Thanks Kindly