Solved

Multiselect for Report Criteria

Posted on 1998-08-14
1
264 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
1 Comment
 
LVL 4

Accepted Solution

by:
tomook earned 50 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Input box criteria 3 19
DCount using "OR" 4 19
Access Migration to Sql Server 2 22
Dlookup issue 4 5
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

759 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

24 Experts available now in Live!

Get 1:1 Help Now