(Msg. 1) Posted: Fri Sep 05, 2008 10:44 am
Post subject: Filter report based on list box and combo box Archived from groups: microsoft>public>access>reports (more info?)
I have been trying to filter repotr based on a list box and combo box. I can
filter the report using either the combo box or list box but I'm stuck in
combining both. I get a type mismatch error message.
Here is the code I'm using.
Listbox is called lstAppealType
Combo box is called =cboHP (format is text)
Dim strWhere As String
Dim ctl As Control
Dim varItem As Variant
'add selected values to string
Set ctl = Forms!frmReports!lstAppealType
For Each varItem In ctl.ItemsSelected
strWhere = strWhere & ctl.ItemData(varItem) & ","
Next varItem
'trim trailing comma
strWhere = Left(strWhere, Len(strWhere) - 1)
'open the report, restricted to the selected items
(Msg. 2) Posted: Fri Sep 05, 2008 2:22 pm
Post subject: Re: Filter report based on list box and combo box [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
brytank44 wrote:
>I have been trying to filter repotr based on a list box and combo box. I can
>filter the report using either the combo box or list box but I'm stuck in
>combining both. I get a type mismatch error message.
>
>Here is the code I'm using.
>
>Listbox is called lstAppealType
>Combo box is called =cboHP (format is text)
>
> Dim strWhere As String
> Dim ctl As Control
> Dim varItem As Variant
>
> 'add selected values to string
> Set ctl = Forms!frmReports!lstAppealType
> For Each varItem In ctl.ItemsSelected
> strWhere = strWhere & ctl.ItemData(varItem) & ","
> Next varItem
> 'trim trailing comma
> strWhere = Left(strWhere, Len(strWhere) - 1)
>
>
> 'open the report, restricted to the selected items
>
>DoCmd.OpenReport "rptAppealCntbyTypeMonthly", acPreview, , "AppealTypeID
>IN(" & strWhere & ")" And "([HP]='" & [Forms]![frmReports]![cboHP] & "'"
With Forms!frmReports
For Each varItem In !lstAppealType.ItemsSelected
strList = strList & "," _
& !lstAppealType.ItemData(varItem)
Next varItem
strWhere = strWhere & " AND " & AppealTypeID IN(" &
Mid(strList, 2) & ")"
If Not IsNull(!cboHP) Then
strWhere = strWhere & " AND HP='" & !cboHP & "'"
End If
End With
'open the report, restricted to the selected items
DoCmd.OpenReport "rptAppealCntbyTypeMonthly", _
acPreview, , Mid(strWhere , 6)
(Msg. 3) Posted: Fri Sep 05, 2008 2:22 pm
Post subject: Re: Filter report based on list box and combo box [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
Thank you. However, it doesn't like the IN the string below. Is it different
if the ApealType Id is a number(long integer)?
> brytank44 wrote:
>
> >I have been trying to filter repotr based on a list box and combo box. I can
> >filter the report using either the combo box or list box but I'm stuck in
> >combining both. I get a type mismatch error message.
> >
> >Here is the code I'm using.
> >
> >Listbox is called lstAppealType
> >Combo box is called =cboHP (format is text)
> >
> > Dim strWhere As String
> > Dim ctl As Control
> > Dim varItem As Variant
> >
> > 'add selected values to string
> > Set ctl = Forms!frmReports!lstAppealType
> > For Each varItem In ctl.ItemsSelected
> > strWhere = strWhere & ctl.ItemData(varItem) & ","
> > Next varItem
> > 'trim trailing comma
> > strWhere = Left(strWhere, Len(strWhere) - 1)
> >
> >
> > 'open the report, restricted to the selected items
> >
> >DoCmd.OpenReport "rptAppealCntbyTypeMonthly", acPreview, , "AppealTypeID
> >IN(" & strWhere & ")" And "([HP]='" & [Forms]![frmReports]![cboHP] & "'"
>
>
> With Forms!frmReports
> For Each varItem In !lstAppealType.ItemsSelected
> strList = strList & "," _
> & !lstAppealType.ItemData(varItem)
> Next varItem
> strWhere = strWhere & " AND " & AppealTypeID IN(" &
> Mid(strList, 2) & ")"
>
> If Not IsNull(!cboHP) Then
> strWhere = strWhere & " AND HP='" & !cboHP & "'"
> End If
> End With
>
> 'open the report, restricted to the selected items
> DoCmd.OpenReport "rptAppealCntbyTypeMonthly", _
> acPreview, , Mid(strWhere , 6)
>
> --
> Marsh
> MVP [MS Access]
>
(Msg. 4) Posted: Fri Sep 05, 2008 4:41 pm
Post subject: Re: Filter report based on list box and combo box [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
brytank44 wrote:
>Thank you. However, it doesn't like the IN the string below. Is it different
>if the ApealType Id is a number(long integer)?
>
>strWhere = strWhere & " AND " & AppealTypeID IN(" & Mid(strList, 2) & ")"
Sorry, there's an extra quote in there, It should be:
All times are: Eastern Time (US & Canada) (change)
Page 1 of 1
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum