Solved

MultiSelect List Filter with Additional filter fields

Posted on 2014-01-20
3
447 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
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now