Solved

Using multi selection list boxes for reports

Posted on 2001-09-17
9
199 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
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
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.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

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