Solved

Using multi selection list boxes for reports

Posted on 2001-09-17
9
201 Views
Last Modified: 2008-03-10
Hi All

On a form used for inputting info for a report I have 2 multi selection list boxes which I want to pass to a report.. I eventually figured out how to do it for one but I need know to be able to do it for 2 or more. The following code is what I ended up with but when you you select from the 2 lists it takes both criteria and prints as if you were running 2 seperate queries and combining the results. I think its combining the 2 criteria as "OR" rather than "AND"

Private Function GetCriteriaRS() As String
   Dim stDocCriteria As String
      Dim VarItm As Variant
    For Each VarItm In lstCompanies.ItemsSelected
      stDocCriteria = stDocCriteria & "[Supplier] = " & lstCompanies.Column(0, VarItm) & " OR "
 Next
  For Each VarItm In List169.ItemsSelected
      stDocCriteria = stDocCriteria & "[Point] = '" & List169.Column(0, VarItm) & "'" & " OR "
         Next
             If stDocCriteria <> "" Then
      stDocCriteria = left(stDocCriteria, Len(stDocCriteria) - 4)
   Else
            stDocCriteria = "True"
   End If
   GetCriteriaRS = stDocCriteria
   End Function


Any suggestions would be greatfully recieved

Regards
Robin
0
Comment
Question by:Robina
[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
9 Comments
 
LVL 6

Accepted Solution

by:
cjswimmer earned 50 total points
ID: 6487800
try this:

Private Function GetCriteriaRS() As String
    Dim stDocCriteria As String
    Dim VarItm As Variant
    If lstCompanies.ItemsSelected.Count > 0 Then
        stDocCriteria = "([Supplier] IN ("
        For Each VarItm In lstCompanies.ItemsSelected
            stDocCriteria = stDocCriteria & lstCompanies.Column(0, VarItm) & ","
        Next
        stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 1) & "))"
    End If
    If List169.ItemsSelected.Count > 0 Then
        If Len(stDocCriteria) Then
            stDocCriteria = stDocCriteria & " AND"
        End If
        stDocCriteria = stDocCriteria & " ([Point] IN ("
        For Each VarItm In List169.ItemsSelected
            stDocCriteria = stDocCriteria & "'" & List169.Column(0, VarItm) & "',"
        Next
        stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 1) & ")"
    End If
    If Not Len(stDocCriteria) Then
        stDocCriteria = "True"
    End If
    GetCriteriaRS = stDocCriteria
End Function
0
 
LVL 6

Expert Comment

by:cjswimmer
ID: 6487806
oops, the 7th to last line should have an extra close parentheses in it like:

stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 1) & "))"
0
 

Author Comment

by:Robina
ID: 6489845
Thanks for the quick answer but sadly it failed to work.  The report now ignores the criteia completely and prints all items.

Regards
Robin
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:cjswimmer
ID: 6490349
ok, locate the patch of code where you call this function.  Add this line of code to it:

Debug.Print GetCriteriaRS

and put a breakpoint on the next line.  (You can add a breakpoint by clicking your mouse on the grey area next to the line you want to stop on)  This will pause the program's execution and allow you to examine the value of all of your variables if you want.  When the program pauses, hit Control-G and the immediate window should pop up.  Copy the string that you see entered there and post it here so I can see the results.
0
 
LVL 6

Expert Comment

by:cjswimmer
ID: 6516932
Robina?
0
 
LVL 6

Expert Comment

by:cjswimmer
ID: 6528584
...
0
 
LVL 6

Expert Comment

by:cjswimmer
ID: 6578886
...
0
 
LVL 54

Expert Comment

by:nico5038
ID: 6983023
for Robina

It's time to clean up this TA, so I will leave a recommendation in Community Support that this question is:
 - Answered by: cjswimmer  
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6997548
Per recommendation, force-accepted by
Netminder
CS Moderator
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

740 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