Solved

Using multi selection list boxes for reports

Posted on 2001-09-17
9
196 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

743 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

10 Experts available now in Live!

Get 1:1 Help Now