WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Filter report based on list box and combo box

 
   Home -> Office other -> Reports RSS
Next:  Problem With Graph X-Axis  
Author Message
brytank44

External


Since: Sep 05, 2008
Posts: 2



(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

DoCmd.OpenReport "rptAppealCntbyTypeMonthly", acPreview, , "AppealTypeID
IN(" & strWhere & ")" And "([HP]='" & [Forms]![frmReports]![cboHP] & "'"
--
doh!!!
Back to top
Login to vote
Marshall Barton

External


Since: Dec 07, 2003
Posts: 6121



(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)

--
Marsh
MVP [MS Access]
Back to top
Login to vote
brytank44

External


Since: Sep 05, 2008
Posts: 2



(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)?

strWhere = strWhere & " AND " & AppealTypeID IN(" & Mid(strList, 2) & ")"
--
doh!!!


"Marshall Barton" wrote:

> 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]
>
Back to top
Login to vote
Marshall Barton

External


Since: Dec 07, 2003
Posts: 6121



(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:

strWhere = strWhere & " AND AppealTypeID IN(" & Mid(strList,
2) & ")"

--
Marsh
MVP [MS Access]
Back to top
Login to vote
Display posts from previous:   
       Home -> Office other -> Reports 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
Categories:
 Windows XP
 Windows Vista
 Windows Other
 Office
  Office Other
 Security
 WinRAR
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET