?
Solved

Using multi selection list boxes for reports

Posted on 2001-09-17
9
Medium Priority
?
208 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 200 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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.
Suggested Courses

777 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