?
Solved

Multiselect for Report Criteria

Posted on 1998-08-14
1
Medium Priority
?
271 Views
Last Modified: 2012-05-04
I have a form with a multiselect list box and another box that multiselect choices are copied to.  There is also an option group with two members.  I am trying to assign code to the Click event of a command button so that when someone makes their choices from the multiselect, then specifies the report they want to view, the proper report will come up showing the information filtered by the multiselect choices.

I'm having a little trouble with this.  Any guidance?
0
Comment
Question by:strovej
[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
1 Comment
 
LVL 4

Accepted Solution

by:
tomook earned 150 total points
ID: 1959226
DoCmd.OpenReport has an optional fourth argument which allows you to specify a WHERE clause, without the WHERE. All you have to do is build the criteria based on the selected items in your list box, and pass it to the DoCmd.OpenReport.
ex. (not tested)
Dim sWhere As String
Dim iCnt1 As Integer

sWhere = ""
For iCnt1 = 1 To Me.SomeListBox.ItemsSelected.Count
    sWhere = sWhere & " AND (FieldInReportQuery = " Me.SomeListBox.ItemsSelected(iCnt1) & ")"
    ' Will need to paste in quotes if your values are strings,
    ' # if dates, ex.
    'sWhere = sWhere & " AND (FieldInReportQuery = '" Me.SomeListBox.ItemsSelected(iCnt1) & "')"

    'sWhere = sWhere & " AND (FieldInReportQuery = #" Me.SomeListBox.ItemsSelected(iCnt1) & "#)"

Next iCnt1
' Strip of first " AND "
If Len(sWhere) > 0 Then
    sWhere = Mid$(sWhere,5)
End If
DoCmd.OpenReport "ReportName", acNormal, , sWhere

0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

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.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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 …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

765 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