Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MultiSelect List Filter with Additional filter fields

Posted on 2014-01-20
3
Medium Priority
?
465 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 85
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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

810 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