B
babs
I was using the post dated 5/28/08 by Klatuu explaining how to set up VB code
for previewing a report based on items slected (many) from a list
box-multiselect.
this is my code below
Private Function BuildWhereCondition(strControl As String) As String
'Set up the WhereCondition Argument for the reports
Dim varItem As Variant
Dim strWhere As String
Dim ctl As Control
Set ctl = Me.Controls(strControl)
Select Case ctl.ItemsSelected.Count
Case 0 'Include All
strWhere = ""
Case 1 'Only One Selected
strWhere = "= " & _
ctl.ItemData(ctl.ItemsSelected(0))
Case Else 'Multiple Selection
strWhere = " IN ("
With ctl
For Each varItem In .ItemsSelected
strWhere = strWhere & .ItemData(varItem) & ", "
Next varItem
End With
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End Select
BuildWhereCondition = strWhere
End Function
On the On click event of the command button to print what is selelcted is
below:
Private Sub Command13_Click()
Dim stDocName As String
Dim strRptFilter As String(Had to ADD this saying that it wasn't
defined-not sure if really a string???)
'To call it, you pass the name of the list box and assign the results to a
'variable:
strRptFilter = BuildWhereCondition("MyListBox")
'Then you use it to open the report:
DoCmd.OpenReport "LaborReport2 BP", acViewPreview, , strRptFilter
End Sub
With all of that I am getting the error
Runtime error 3075
Syntax error(missing operator) in query expression 'In(16,111,12)'
the Job # is the bound column and it is a number field.
any ideas on how to get rid of the error???
thanks,
barb
for previewing a report based on items slected (many) from a list
box-multiselect.
this is my code below
Private Function BuildWhereCondition(strControl As String) As String
'Set up the WhereCondition Argument for the reports
Dim varItem As Variant
Dim strWhere As String
Dim ctl As Control
Set ctl = Me.Controls(strControl)
Select Case ctl.ItemsSelected.Count
Case 0 'Include All
strWhere = ""
Case 1 'Only One Selected
strWhere = "= " & _
ctl.ItemData(ctl.ItemsSelected(0))
Case Else 'Multiple Selection
strWhere = " IN ("
With ctl
For Each varItem In .ItemsSelected
strWhere = strWhere & .ItemData(varItem) & ", "
Next varItem
End With
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End Select
BuildWhereCondition = strWhere
End Function
On the On click event of the command button to print what is selelcted is
below:
Private Sub Command13_Click()
Dim stDocName As String
Dim strRptFilter As String(Had to ADD this saying that it wasn't
defined-not sure if really a string???)
'To call it, you pass the name of the list box and assign the results to a
'variable:
strRptFilter = BuildWhereCondition("MyListBox")
'Then you use it to open the report:
DoCmd.OpenReport "LaborReport2 BP", acViewPreview, , strRptFilter
End Sub
With all of that I am getting the error
Runtime error 3075
Syntax error(missing operator) in query expression 'In(16,111,12)'
the Job # is the bound column and it is a number field.
any ideas on how to get rid of the error???
thanks,
barb