Solved

MultiSelect List Filter with Additional filter fields

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

929 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

14 Experts available now in Live!

Get 1:1 Help Now