Solved

Using multi selection list boxes for reports

Posted on 2001-09-17
9
205 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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.
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.

728 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