473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Filtering a Report based on a list box

Hi, i have managed to filter a report based on selections made in a list box but am totally confused with a message box that appears everytime i run my report.

Let me explain (i apologise for being long-winded)...

I have a query called qry Queue Filtered SLA Position,
within this query there is a field 'Queue Group'.
I also have a report called rpt Queue Filtered SLA Position

I have a listbox called ListFilter. It's rowsource is equal to qry Queue Filtered SLA Position. The multiselect property is set to 'simple'.

I have the following code in my form :

Expand|Select|Wrap|Line Numbers
  1. Private Function GetCriteria() As String
  2.    Dim stDocCriteria As String
  3.    Dim VarItm As Variant
  4.    For Each VarItm In ListFilter.ItemsSelected
  5.   stDocCriteria = stDocCriteria & "[Queue Group] = " & ListFilter.Column(0, VarItm) & " OR "
  6.    Next
  7.    If stDocCriteria <> "" Then
  8.   stDocCriteria = Left(stDocCriteria, Len(stDocCriteria) - 4)
  9.    Else
  10.   stDocCriteria = "True"
  11.    End If
  12.    GetCriteria = stDocCriteria
  13. End Function
  14.  
And a button to request the report which has the following code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2. DoCmd.OpenReport "rpt Queue Filtered SLA Position", acPreview, , GetCriteria()
  3. End Sub
  4.  
Now, when i make a selection from the listbox and click the button i get a message box entitled 'Enter Parameter Value' with the selection i have just made above the text box! If i then type in the selection i have made and click OK, the report is produced as intended, i.e. with just my selection.

Why, oh why does this message box appear ?? What is the point of making a selection only to have to type it in ?

Your comments/advise is greatly appreciated and needed.
Jun 26 '07 #1
5 2668
I have a developement, i have realised that the problem is the 'Get Criteria()' part of the statement:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "rpt Queue Filtered SLA Position", acPreview, , GetCriteria()
where the GetCriteria() is the WHERE condition. It is recognising the selection(s) as [selection] and not "selection" therefore is asking for the value.

However i am still at a loss as to how to rectify this, can anyone assist??
Jun 26 '07 #2
kepston
97 Expert
I have had trouble building string criteria in the past too.
In this case I think you need to put in "" to add quotes around your listbox values.
Expand|Select|Wrap|Line Numbers
  1. stDocCriteria = stDocCriteria & "[Queue Group] = """ & ListFilter.Column(0, VarItm) & """ OR "
I hope that's clear!
Jun 26 '07 #3
I have had trouble building string criteria in the past too.
In this case I think you need to put in "" to add quotes around your listbox values.
Expand|Select|Wrap|Line Numbers
  1. stDocCriteria = stDocCriteria & "[Queue Group] = """ & ListFilter.Column(0, VarItm) & """ OR "
I hope that's clear!

Thank you very much, i knew it had to recognise it as a string and have just had chance to check this out before leaving work; great...it works!!!.

Cheers
Jun 26 '07 #4
NeoPa
32,556 Expert Mod 16PB
That's a good answer, to double up the quotes (""), but a better answer for working in SQL is to use the single-quotes (') instead for strings (NB ONLY in SQL - VBA doesn't work with them).
Jul 3 '07 #5
NeoPa
32,556 Expert Mod 16PB
I found this link to clarify further (Quotes (') and Double-Quotes (") - Where and When to use them.).
Jul 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
1
by: diskoduro | last post by:
Hi! I'm trying to get help to an unexpected problem that has appeared while I was writing a new application. I want to opeon a report of product sales by filtering previously from a listbox in a...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
0
by: Scott Loupin | last post by:
I've got two databases with similar data in them (WestSide and EastSide). I've set up two identical reports that is filtered by date and the client name. I'm using one form to do the filtering. ...
1
by: mstery | last post by:
I have a report generated via an ID selection made in a dropdown on a form. The report filters by an on click event in a preview report button on the form. Everything in the report, including...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
2
by: Zlatko Matić | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
1
by: jilppe | last post by:
I am creating a report based on a crosstab (BodyPart). This crosstab counts the number of incidents for each body part by month. However the data is for different years and I would like the user to...
3
by: paquer | last post by:
On my Main form I have a Command Button that opens a Subform in order to create a new Subform record. At this point I want the subform to show only the new record being created. Not all the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.