473,386 Members | 1,630 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,386 software developers and data experts.

Selecting "All" in a combobox

Folks,

Need help getting my code to work. I am trying to select "All" in a combobox for a query in access.

See my sql code I added to the Row Source:
Expand|Select|Wrap|Line Numbers
  1. Select Managers AS Filter, Managers FROM dbo_ManagerList UNION SELECT '*' AS Filter, " All" AS Managers FROM dbo_ManagerList GROUP BY dbo_ManagerList.Managers
  2. ORDER BY dbo_ManagerList.Managers;
Bound Column = 1
Column Count = 2
Column Widths = 0; 2

Looks like the query builder is working correctly but not translating to the actual query I am trying to configure. My normal values work just not the all function.

Any assistance would be highly appreciated.

Thanks,

Chris
Jul 10 '18 #1

✓ answered by NeoPa

CVincent:
If this is true this is the part I need help with lol
Yes. That would make sense.

How about you tell us what you're using at the moment. Typically people often try to create SQL that filters on ='*' or ='{Selected Value}' if you prefer. This won't work as a wildcard as that only works as expected when using the Like keyword.

So, it should be more like ... Like '{Selected Value}'. Let us know if you still have problems once you've looked at that.

BTW, I discovered after setting up a test to match your system that using a values-only SELECT query, which is quite valid normally, is not valid in Jet/ACE SQL when using UNION. That's why my code didn't work and using the extra FROM and GROUP BY clauses was required - unfortunately. It seems that wasn't really the question you were trying to ask though. I just wanted to explain why you were getting what you were getting.

34 3253
PhilOfWalton
1,430 Expert 1GB
This SQL assumes the bound column is 2 (MemberId - Primary Key), It is a sample but you can adjust it as required

Expand|Select|Wrap|Line Numbers
  1.     StrSQL = "SELECT " & Chr$(34) & "<All>" & Chr$(34) & " AS MemSurName, " & Chr$(34) & Chr$(34) & " AS MemFirstName, 0 AS MemberID, 0 AS SortOrder FROM Member "
  2.     StrSQL = StrSQL & "UNION SELECT MemSurName, MemFirstName, MemberID, MemSurName AS SortOrder From Member "
  3.     StrSQL = StrSQL & "ORDER BY SortOrder, MemSurName, MemFirstName;"
  4.  
Phil
Jul 10 '18 #2
NeoPa
32,556 Expert Mod 16PB
Hi Chris.

It seems your problem is that your GROUP BY and ORDER BY clauses, that are outside of the UNION part remember, use expressions qualified to only one side of the UNION.

Try using :
Expand|Select|Wrap|Line Numbers
  1. ...
  2. GROUP BY [Managers]
  3. ORDER BY [Managers]
Jul 11 '18 #3
Gents,

Thanks for the feedback... unfortunately neither worked?

Is there any other details I can post that might help you find my mistake?

Thanks
Jul 12 '18 #4
NeoPa
32,556 Expert Mod 16PB
Please post the exact SQL you tried based on my suggestion for us to consider.
Jul 12 '18 #5
See exact code below:

Expand|Select|Wrap|Line Numbers
  1. Select Managers AS Filter, Managers FROM dbo_ManagerList UNION SELECT '*' AS Filter, "All" AS Managers FROM dbo_ManagerList GROUP BY Managers
  2. ORDER BY Managers;
Query builder looks to be correct:

Showing to columns one called Filter the other Managers with the same rows + included "All" row.

Thanks Neo
Jul 12 '18 #6
NeoPa
32,556 Expert Mod 16PB
CVincent78:
Showing to columns one called Filter the other Managers with the same rows + included "All" row.
Are you now saying that works after all?
Or should I still be looking to see where this version fails?
Jul 12 '18 #7
Nope still doesn't work.
Jul 12 '18 #8
twinnyfo
3,653 Expert Mod 2GB
I guess I'm just throwing this out there, but, doesn' the syntax SELECT '*' AS Filter imply (in this particular situation with the UNION QUERY), that there is only one field in dbo_ManagerList, and that if there are multiple fields in that table, this will cause problems with the UNION?

Or am I totally off base, with this one?
Jul 12 '18 #9
There is only one field in the dbo_ManagerList. When I run the SQL script in the combobox query it creates the filter column and add the "All" row to both
Jul 12 '18 #10
PhilOfWalton
1,430 Expert 1GB
You apparently made no attempt to modify the SQL I sent you which I know works.
Right, now we have your table name and assuming you have a primary key called ManagerID and a field called ManagerNamecthen try

Expand|Select|Wrap|Line Numbers
  1. StrSQL = "SELECT " & Chr$(34) & "<All>" & Chr$(34) & " AS ManagerName, " ,
  2. StrSQL = StrSQL & "0 AS ManagerID, 0 AS SortOrder FROM dbo_ManagerList "
  3. StrSQL = StrSQL & "UNION SELECT ManagerName,  ManagerID, 
  4. StrSQL = StrSQL & "ManagerName AS SortOrder From dbo_ManagerList "
  5. StrSQL = StrSQL & "ORDER BY SortOrder, ManagerName;"
  6.  
Phil
Jul 12 '18 #11
Phil,

Definitely tried your code.

There is no ManagerID column. There is only a dbo table called dbo_ManagerList and a column named [Managers] with only 5 manager names for rows.

I modified your code (See Below)

Expand|Select|Wrap|Line Numbers
  1. 1.    StrSQL = "SELECT " & Chr$(34) & "<All>" & Chr$(34) & " AS Manager, " ,
  2. 2.    StrSQL = StrSQL & "0 AS Managers, 0 AS SortOrder FROM dbo_ManagerList "
  3. 3.    StrSQL = StrSQL & "UNION SELECT Managers,  
  4. 4.    StrSQL = StrSQL & "Managers AS SortOrder From dbo_ManagerList "
  5. 5.    StrSQL = StrSQL & "ORDER BY SortOrder, Managers;"
  6. 6.     StrSQL = "SELECT " & Chr$(34) & "<All>" & Chr$(34) & " AS Managers, " ,
Gives me a Invalid SQL statement; 'Delete', 'Insert', 'Procedure', 'Select' or 'UPDATE'.

Thanks for trying to walk me through this.
Jul 12 '18 #12
NeoPa
32,556 Expert Mod 16PB
Please try this - and if it doesn't work then tell us what does go wrong. Trying to guess what's wrong while you observe and wait isn't any better use of your time than it is ours ;-)
Expand|Select|Wrap|Line Numbers
  1. SELECT   [Managers] AS [Filter]
  2.        , [Managers]
  3. FROM     [dbo_ManagerList]
  4. UNION
  5. SELECT   '*' AS [Filter]
  6.        , 'All' AS [Managers]
  7. GROUP BY [Managers]
  8. ORDER BY [Managers]
Jul 12 '18 #13
Neo,

I added the code exactly the way you posted and I get a SELECT statement includes a reserved word or an argument name that is misspelled, or the punctuation is incorrect.

Maybe I should step back and explain what I am trying to do in more detail.

I have a main form page that I have a combo box that pulls from a dbo table of manager names. (The Row Source) When the user selects the name of the manager they want it will change the manager in a query to that name and update a subform report graph of total back log hours. Everything works perfectly, but I would also like to see all the managers total back log hours. This is where I am stuck it seems like the query used to update the graph isn't accepting the wildcard '*'... hope this explains things better. Once again I appreciate your guy's time in helping me resolve.
Jul 12 '18 #14
Rabbit
12,516 Expert Mod 8TB
How are you trying to use this wildcard? Because Field = '*' is not going to work. You need to use the LIKE operator.
Jul 12 '18 #15
Rabbit,

Using the SQL wildcard in the SQL builder of the row source for the combobox.

Expand|Select|Wrap|Line Numbers
  1. Select Managers AS Filter, Managers FROM dbo_ManagerList UNION SELECT '*' AS Filter, "All" AS Managers FROM dbo_ManagerList GROUP BY Managers
  2. ORDER BY Managers;
  3.  
If I pick one of the managers the query which is mapped to the combo box updates correctly but if I pick the "All" row the query goes blank and acts like it doesn't recognize the wildcard.
Jul 12 '18 #16
Rabbit
12,516 Expert Mod 8TB
That's how you're populating the drop-down list. That's not what I'm asking about, how are you trying to make use of the value they select?
Jul 12 '18 #17
Pretty sure it is outlined here:

Expand|Select|Wrap|Line Numbers
  1. UNION SELECT '*' AS Filter,
But I could easily be wrong....
Jul 12 '18 #18
Rabbit
12,516 Expert Mod 8TB
That is how you're adding the asterisk to the drop down.

That's not what I'm looking for. I'm looking for how you make use of that asterisk to filter the records.
Jul 12 '18 #19
I thought that the union function would insert the wildcard into the combo mapping in the query when selecting "All" if it doesn't then I think we found my problem. If this is true this is the part I need help with lol
Jul 12 '18 #20
zmbd
5,501 Expert Mod 4TB
Ok, so I have a very simply union query that I use a combobox row source to select a year from one of my databases for sample reports:
Expand|Select|Wrap|Line Numbers
  1. SELECT ZUNION.ZSelectYear
  2. FROM 
  3.   (SELECT 1 as ZOrder
  4.     ,  "All" as ZSelectYear 
  5.    FROM t_testyear 
  6.    UNION SELECT 2 as Zorder
  7.     , t_testYear.PK_testYear AS "Zyear" 
  8.    FROM t_testYear)  AS ZUNION
  9. ORDER BY ZUNION.Zorder, ZUNION.ZSelectYear DESC;
On the form I have a control button [on_click] event
Expand|Select|Wrap|Line Numbers
  1. Private Sub zctrl_btn_OK_Click()
  2.   If [TempVars]![reportyears] & "" = "" Then
  3.     [TempVars].Add "ReportYears", "*"
  4.   End If
  5.   '
  6.   If [TempVars]![openreportfor] & "" = "" Then
  7.     [TempVars].Add "OpenReportFor", "1"
  8.   End If
  9.   '
  10.   If Not Me.zctrl_cbo_selectyear = "All" Then
  11.     [TempVars]![reportyears] = Me.zctrl_cbo_selectyear.Value
  12.   Else
  13.     [TempVars]![reportyears] = "*"
  14.   End If
  15.   [TempVars]![openreportfor] = Me.zctrl_option_OpenReportFor.Value
  16.   '
  17.   DoCmd.Close acForm, Me.Name, acSaveNo
  18. End Sub
That's only one way to handle the CBOX return so your mileage may vary :)

I'm using the [TempVars] object to pass the year value to the query that my report is based on. I use this same report to show the results for a single sample as well as the group of samples - the query is quite long but the basic idea would be

Expand|Select|Wrap|Line Numbers
  1. SELECT (a bunch of fields here)
  2. FROM (a bunch of joins here)
  3. WHERE 
  4.  ((t_testkit.fk_testYear) Like [TempVars]![ReportYears])
  5.    AND (other [TempVar] references));
Jul 12 '18 #21
Rabbit
12,516 Expert Mod 8TB
would insert the wildcard into the combo mapping in the query when selecting "All"
It will, but that doesn't mean the query is set up to use it correctly. That's why I was asking how you're trying to use it. To make sure you set up that query correctly.

We still need to see that btw.
Jul 12 '18 #22
NeoPa
32,556 Expert Mod 16PB
CVincent:
If this is true this is the part I need help with lol
Yes. That would make sense.

How about you tell us what you're using at the moment. Typically people often try to create SQL that filters on ='*' or ='{Selected Value}' if you prefer. This won't work as a wildcard as that only works as expected when using the Like keyword.

So, it should be more like ... Like '{Selected Value}'. Let us know if you still have problems once you've looked at that.

BTW, I discovered after setting up a test to match your system that using a values-only SELECT query, which is quite valid normally, is not valid in Jet/ACE SQL when using UNION. That's why my code didn't work and using the extra FROM and GROUP BY clauses was required - unfortunately. It seems that wasn't really the question you were trying to ask though. I just wanted to explain why you were getting what you were getting.
Jul 12 '18 #23
Morning Folks,

First totally appreciate your guys efforts. Neo I tried the LIKE operator a couple days ago but SQL wont let me use it after a SELECT operator.

Rabbit,

See the posted query below:

Expand|Select|Wrap|Line Numbers
  1. SELECT dbo_KAI_Project_Tracker_Table.AssignedEngineer, dbo_KAI_Project_Tracker_Table.ProjectName, IIf([EngHoursremaining]<0,[EstimatedHourstoComplete],[EngHoursRemaining]) AS Hours, dbo_KAI_Project_Tracker_Table.CustomerName, dbo_KAI_Project_Tracker_Table.CostCategory, dbo_KAI_Project_Tracker_Table.Status, dbo_KAI_Project_Tracker_Table.Division, [dbo_Staff List].Manager
  2. FROM dbo_KAI_Project_Tracker_Table INNER JOIN ([dbo_Staff List] INNER JOIN dbo_ManagerList ON [dbo_Staff List].Manager = dbo_ManagerList.Managers) ON dbo_KAI_Project_Tracker_Table.AssignedEngineer = [dbo_Staff List].Staff
  3. WHERE (((dbo_KAI_Project_Tracker_Table.AssignedEngineer) Is Not Null And (dbo_KAI_Project_Tracker_Table.AssignedEngineer) Not Like "Not assigned" And (dbo_KAI_Project_Tracker_Table.AssignedEngineer) Not Like "mfg Engineering") AND ((dbo_KAI_Project_Tracker_Table.CustomerName)<>"Gleason Works") AND ((dbo_KAI_Project_Tracker_Table.Status)<>"complete") AND (([dbo_Staff List].Manager)=[Forms]![FRM_MainPage]![CB_ManagerFilter]));
As discussed I have a combo box on a form page that updates a query and then a report (The report is a subform on the main form) to reflect engineering hours by manager. The intent of this trilogy is to be able to select "All" So I can see the total backlog hours for the engineering platform as a whole.

Again appreciate everyone's time... hopefully we solve it and save the next guy some time.

C.
Jul 13 '18 #24
twinnyfo
3,653 Expert Mod 2GB
I believe what NeoPa was referring to was having the Like operator in your WHERE statement. When you place “*” directly after SELECT you are saying you want all FIELDS. I think what you want is all RECORDS that meet certain criteria. Thus:
Expand|Select|Wrap|Line Numbers
  1. WHERE [FieldName] Like 'Criteria*'
Jul 13 '18 #25
Rabbit
12,516 Expert Mod 8TB
This is what I was talking about earlier.
Expand|Select|Wrap|Line Numbers
  1. [dbo_Staff List].Manager)=[Forms]![FRM_MainPage]![CB_ManagerFilter]
You can't use an equals with wildcards. They only work with the LIKE operator.
Jul 13 '18 #26
Alright gents,

I replaced the = with LIKE in the Query. Which one interesting thing is when I first open the database it shows all managers, but once I pick "All" it goes back to blank. Picking individual manager still works.

Twinny,

I added:

Expand|Select|Wrap|Line Numbers
  1. WHERE [Managers] LIKE "criteria*" 
To the rowsource SQL script but it didn't make any difference.

Tried it on both sides of the UNION function.

Thoughts?
Jul 13 '18 #27
NeoPa
32,556 Expert Mod 16PB
Hi Chris.

I was hoping you wouldn't be misled by Twinny's post #25. You don't add an asterisk (*), nor do you use a literal string value. I believe it was intended more as an illustration than an instruction per se.

You either use a direct reference to the form control within the SQL (Similar to Rabbit's suggestion but don't rely on his bracketing.), or you build the SQL something like :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT Blah, blah, blah " _
  2.        & "FROM   [YourTable]
  3.        & "WHERE  ([Manager] Like '%V')"
  4. strSQL = Replace(strSQL, "%V", Me.cboManagerFilter)
Assuming the code is associated with the Form itself and the ComboBox control is called [cboManagerFilter].
Jul 13 '18 #28
Neo,

Do I add this into the rowsource SQL code or the Query SQL code?

Thanks so much guys.... I have learned a lot in the last couple days.

C.
Jul 13 '18 #29
PhilOfWalton
1,430 Expert 1GB
This has gone on far too long.

Firstly your dbo_ManagerList should have a ManagerID as an Autonumber Primary Key. Why? It is conceivable that you may have 2 managers with the same name.

Use the SQL I posted earlier (Post 11) as the RowSource of the Combo Box.

Ensure all your forms & Reports contain the Field "ManagerID"

The whatever form or report you want to filter, build some code like
Expand|Select|Wrap|Line Numbers
  1. Sub CB_ManagerFilter_AfterUpdate
  2.  
  3.     Dim Fltr as String
  4.  
  5.     With Me.SubformName.Form       ' This is the name of the 
  6.                                    ' Subform on Your Main Form
  7.         If ManagerID = 0 then      ' <All> selected
  8.             .FilterOn = False      ' No Filter
  9.         Else
  10.             Fltr = "ManagerID = " & CB_ManagerFilterCB  ' Combo
  11.             ' Box (The Cound Column)
  12.             .FilterOn = True       ' Apply the Filter
  13.         End If
  14.     End With
  15. End Sub
  16.  
Phil
Jul 13 '18 #30
NeoPa
32,556 Expert Mod 16PB
CVincent78:
Do I add this into the rowsource SQL code or the Query SQL code?
You have to understand what is being explained here and use this understanding to create the SQL used to filter your object, whatever that is, that needs to be filtered based on this selection.

This could be by setting a .Filter property of a Form or Report, or it could be to change the WHERE clause of some query.

Only you know what that is, but the concept has been explained clearly and it's now down to you to understand that and build on what you have with that new understanding.

We aren't here to spoon-feed you. At some point you need to grab the concept and go with it. That's now.

We can still help, but we do expect you to get with it and start to work things out for yourself when you can. We're pretty well at that point now.
Jul 14 '18 #31
Thanks guys.. going to tackle it this weekend.

I will let you know how it works out.
Jul 17 '18 #32
NeoPa
32,556 Expert Mod 16PB
8-)
Good luck :-)
Jul 17 '18 #33
Alright got it! Looks like my original code as well as NeoPa's code in the SQL builder was correct all along :)
My problem was my subform was a report I used to build a chart. Once I deleted the subform and added a chart using the Query (Qry_EngHoursbyDivision) directly on the main form (Frm_MainPage) everything worked perfect.

Hope that made sense folks... appreciate everyone's time. Guessing this is the reason everyone else's solution didn't work, but I don't have the time to look into it today.

C.
Jul 17 '18 #34
NeoPa
32,556 Expert Mod 16PB
Glad to hear it's all working well now.

Cheers.
Jul 18 '18 #35

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

Similar topics

14
by: Norm | last post by:
Hi, Each time the user selects an item from a combobox, I want that string to get appended to the values that were already selected. The result is that the combo is accumulating text each time...
5
by: Claudio Di Flumeri | last post by:
Hi all, Iive found this bug int the VB combobox and I'd like to know if there is a way to solve it... Put a combobox in a form, and fill it with these 3 items: - athens - berlin - chicago ...
8
by: Gregory A Greenman | last post by:
I have a minor, but somewhat frustrating, problem. In a program I'm working on, I've got a tabcontrol that contains several other controls, a few of which are comboboxes. In the IDE, one of the...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
2
by: murdock | last post by:
I am having an issue with graphical corruption upon re-selecting a combobox which upon 'selected index change' event should list file names in that folder in a separate combobox. Here is the code:...
8
by: =?Utf-8?B?RyBIdXN0aXM=?= | last post by:
This is the 2nd time posting so sorry for duplications. I am using VB.NT 2005 & a standard Combobox. I've been wracking my brain over this problem for a over a month & cannot seem to find a way to...
0
by: Manikandan | last post by:
Hi, I'm working with .NET framework 1.1 I'm manipulating a excel file using Microsoft Excel 9.0 Object Library. Reading and writing to ordinary cells in excel are fine. I have a excel file, it...
19
by: billa856 | last post by:
Hi, I have to use the table(PRODUCTION) already generated in MS Access in which all fields are of TEXT type.fields like (orderdate,palletno,customercode,itemno,pono,carto n,pcs,totalquantity)Now i...
1
by: beemomo | last post by:
hi everyone! i need to display all the data of a record in a form by selecting the value of combobox. for example when i select a Project_No display in combobox, the correspondence data of that...
10
by: simaonobrega | last post by:
Dear Bytes community, Framework: I have created a form using the "Form Design" tool. On the form property sheet, it was added to the Record Source the table which contained the fields that I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.