Solved

MultiSelect List Filter with Additional filter fields

Posted on 2014-01-20
3
458 Views
Last Modified: 2014-01-21
What I have is an Access report that is filtered by a multi-select list-box.  So the end user is presented with the list box and then selects a button the opens the filtered report.  But now the user wants and additional list-box filter called sSF or Square Feet.  So now the query needs to have Categories and Square Feet.  

Right now I was Here is my code.  I need to add the additional filter to the DoCmd somehow?

Private Sub cmdOpenReport_Click()
  On Error GoTo Err_cmdOpenReport_Click
  Dim sSF           As String
  Dim strWhere      As String
  Dim ctl           As Control
  Dim varItem       As Variant

  'make sure a selection has been made
  If Me.lstCategories.ItemsSelected.Count = 0 Then
    MsgBox "Must select at least 1 Category"
    Exit Sub
  End If

  'add selected values to string
  Set ctl = Me.lstCategories
  For Each varItem In ctl.ItemsSelected
    strWhere = strWhere & ctl.ItemData(varItem) & ","
  Next varItem
  'trim trailing comma
  strWhere = Left(strWhere, Len(strWhere) - 1)
  
  ' Square Feet field
Select Case Me.cboBigBox
  Case "Normal Report"
    sSF = "[SizeSmall]>=0"
  Case "Less than 5,000 SF"
    sSF = "[SizeSmall]<5000"
  Case "5,000 to 10,000 SF"
    sSF = "[SizeSmall]>=5000 AND [SizeSmall]<10000"
  Case "10,000 to 20,000 SF"
    sSF = "[SizeSmall]>=10000 AND [SizeSmall]<20000"
  Case "20,000 and above"
    sSF = "[SizeSmall]>=20000"
  Case Else
End Select

  'open the report, restricted to the selected items
  
  'If Len(sSF) > 0 Then strFilter = "[CategoryID] " & strWhere & " AND " & sSF

  DoCmd.OpenReport "FilteredReport", acViewReport, , "tblCategories.CategoryID IN(" & strWhere & ")"

Exit_cmdOpenReport_Click:
  Exit Sub

Err_cmdOpenReport_Click:
  MsgBox Err.Description
  Resume Exit_cmdOpenReport_Click

End Sub

Open in new window

0
Comment
Question by:napsternova
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84
ID: 39795822
I don't quite understand what you need. It looks like your code is using both Category and SquareFeet when creating your WHERE statement. If so, and if the field "SizeSmall" is included in the Recordsource of your report, then it should work.

Does your code not work? If not, what happens when you run it? Do you get an error? If you do, post the details of the error.
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 39795825
Try this, replace lines 39 to 40 with the following:
strFilter = "tblCategories.CategoryID IN(" & strWhere & ")"
If Len(sSF) > 0 Then strFilter = strFilter &  " AND " & sSF
DoCmd.OpenReport "FilteredReport", acViewReport, , strFilter

Open in new window

Also don't forget to Dim your strFilter variable.

Ron
0
 

Author Closing Comment

by:napsternova
ID: 39797129
Awesome work.  That did the trick. Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question