B
Bob Wickham
Hello,
I have been adapting some code written by Albert D Kallal to build a
Where string from a multi-select list box.
The code compiles but when I click the button I get an error.
Run-time error: 3075
Syntax error (missing operator)in query expression 'WHERE [Lender] IN
('6'))'
Clicking the DeBug button highlights this line in the Sub
DoCmd.OpenReport "rptCommissionReceivedByDate", acViewPreview, , strWhere
If nothing is selected in the list box it works fine and displays all
the records in the report.
Can anybody see where I'm going wrong with this
Bob Wickham
------------------------------------------------------------
Private Sub cmdPreview2_Click()
Dim strWhere As String
strWhere = BuildWhere()
DoCmd.OpenReport "rptCommissionReceivedByDate", acViewPreview, ,
strWhere
End Sub
Private Function BuildWhere() As String
Dim strWhere As String, strIN As String
' create the IN string by looping thru the listbox
' where "lstLender" is the name of the list box on the form
For i = 0 To lstLender.ListCount - 1
If lstLender.Selected(i) Then
If lstLender.Column(0, i) = "All" Then
strIN = ""
Exit For
End If
If strIN <> "" Then strIN = strIN & ","
strIN = strIN & "'" & lstLender.Column(0, i) & "'"
End If
Next i
If strIN <> "" Then
strWhere = " WHERE [Lender] IN (" & strIN & ")"
End If
BuildWhere = strWhere
End Function
I have been adapting some code written by Albert D Kallal to build a
Where string from a multi-select list box.
The code compiles but when I click the button I get an error.
Run-time error: 3075
Syntax error (missing operator)in query expression 'WHERE [Lender] IN
('6'))'
Clicking the DeBug button highlights this line in the Sub
DoCmd.OpenReport "rptCommissionReceivedByDate", acViewPreview, , strWhere
If nothing is selected in the list box it works fine and displays all
the records in the report.
Can anybody see where I'm going wrong with this
Bob Wickham
------------------------------------------------------------
Private Sub cmdPreview2_Click()
Dim strWhere As String
strWhere = BuildWhere()
DoCmd.OpenReport "rptCommissionReceivedByDate", acViewPreview, ,
strWhere
End Sub
Private Function BuildWhere() As String
Dim strWhere As String, strIN As String
' create the IN string by looping thru the listbox
' where "lstLender" is the name of the list box on the form
For i = 0 To lstLender.ListCount - 1
If lstLender.Selected(i) Then
If lstLender.Column(0, i) = "All" Then
strIN = ""
Exit For
End If
If strIN <> "" Then strIN = strIN & ","
strIN = strIN & "'" & lstLender.Column(0, i) & "'"
End If
Next i
If strIN <> "" Then
strWhere = " WHERE [Lender] IN (" & strIN & ")"
End If
BuildWhere = strWhere
End Function