Solved

MultiSelect List Filter with Additional filter fields

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

860 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