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

Add "All" to Combo Box and Use "All" as Criteria in Query

Hi Everyone-

I have a question about how to add and then use the "All" selection in
a combo box. I am trying to figure out how to:

(1) add "All" as a selection to a combo box and then

(2) how to use the selection "All" as criteria for a field in a
query, which is used to generate data for a report.
I use 3 different objects on a form as criteria for a query that is
used to generate a report. 2 of these objects are text boxes, and 1 is
a combo box.

I have a simple form named, frmTeam, which has: 2 text boxes, 1 combo
box, and 2 command buttons. The data from the 2 text boxes and combo
box are used as criteria in a query to generate a report.

The 2 text boxes are used to record a user-defined date range. The text
box named, txtBeginDate, stores the beginning date, and the text box
named, txtEndDate, stores the ending date. The dates from these 2 text
boxes are used in a "Between...And" statement as part of the
criteria in my query.

Between [forms]![frmTeam]![txtBeginDate] And
[forms]![frmTeam]![txtEndDate]
The combo box named, cboTeam, displays 2 fields from the table named,
Team. The combo box displays the fields: TeamID and TeamName. The 1st
column, TeamID, is the bound column. The selection in this combo box is
used, along with the 2 dates in the text boxes, as criteria in my
query.

[forms]![frmTeam]![cboTeam]
The 2 command buttons are very simple and straight forward. One command
button is used to preview my report, and the other command button
closes the form.
Right now, everything works fine. I select a Team, i.e. Atlanta Braves,
enter a Beginning Date (1/1/05) and an Ending Date (7/20/05), and my
query will list the names of all the team members that joined the team
between those 2 dates.

I want to add the selection "All: to my combo box so that I can see
all of the names of people who joined a team between those 2 dates.

For example: If I select "All" in my combo box and 1/1/05 as the
beginning date and 7/20/05 as my ending date, I want to see info such
as:

Atlanta Braves - John Doe
Atlanta Braves - Ray Park
New York Mets - Tom Jones
Texas Rangers - George Bush
I don't know how to correctly add the "All" selection to my combo
box and then use it as criteria for my query.
Tables:

Team
TeamID (Text & Primary Key)
TeamName

TeamMember
TeamMemberID (Text & Primary Key)
LastName
FirstName
JoinDate (Date)

Thanks,

Megan :-)

Nov 13 '05 #1
4 7116

i see how to add "all" to a combo box. but how do i use its value?

for instance:

my combo box displays: teamid | teamname from my table team.

teamid | teamname
1 atlanta braves
2 new york mets
3 florida marlins

whichever team i select, the combo box stores their primary key. if i
select "florida marlins" the value stored in my combo box is "3."

i then use this value of "3" as criteria in my query.

the query joins 2 tables: team and teammember.

the table team has:
teamid (pkl)
teamname

the table teammember has:
teammemberid (pk)
lastname
firstname
joindate (date)
teamid (fk to table team)
so when i select "florida marlins," my combo box saves "3" as its
value. "3" is then used in a query to limit the results.

questions:

if i add "all" to my combo box, what is its value?

how can i pass "all" to my query so that it returns all the teams?

i understand the union query i think, but how do i assign a value to
"all?"

thanks,

megan :-)

Nov 13 '05 #3
you could write the query dynamically in code, and then only add the where
clause if teamid >0 or something.
or
your WHERE clause could be based on the teamname instead of the id, and then
you could base your where clause on "like" rather then "=". Then you could
put "*" in the combobox under teamname, and it would come out: WHERE
teamname like '*', giving you all teams.

I know these are not complete solutions, but they might give you some ideas.

<me**************@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...

i see how to add "all" to a combo box. but how do i use its value?

for instance:

my combo box displays: teamid | teamname from my table team.

teamid | teamname
1 atlanta braves
2 new york mets
3 florida marlins

whichever team i select, the combo box stores their primary key. if i
select "florida marlins" the value stored in my combo box is "3."

i then use this value of "3" as criteria in my query.

the query joins 2 tables: team and teammember.

the table team has:
teamid (pkl)
teamname

the table teammember has:
teammemberid (pk)
lastname
firstname
joindate (date)
teamid (fk to table team)
so when i select "florida marlins," my combo box saves "3" as its
value. "3" is then used in a query to limit the results.

questions:

if i add "all" to my combo box, what is its value?

how can i pass "all" to my query so that it returns all the teams?

i understand the union query i think, but how do i assign a value to
"all?"

thanks,

megan :-)

Nov 13 '05 #4
One way to do this is to build your filter on the fly. Something like
this... NOT TESTED... so beware.

Sub cmdOpenReport '<== code behind your button to open your
report
strReport = me.cboReport

'--- if both date fields are filled in, add the date criteria
to the filter
if Not IsNull(me.dtStartDate) and Not IsNull(Me.dtEndDate)
Then
strFilter = "BETWEEN #" & dtStartDate & "# AND #" &
dtEndDate & "#"
end if

'---if the cboTeam combo is not ALL then DO add the filter,
otherwise, leave it off.
if cboTeam.columns(1)<>"All" then
strFilter = strFilter + " AND "
strFilter = strFilter & " Team = " & cboTeamID
end if

docmd.openreport "SomeReport", strFilter
end sub

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dale Ring | last post by:
Access 2000 I am trying to add "ALL" to a combo that is used to filter a query. When "ALL" is selected no records show instead of ALL records showing. I have setup a "dummy" table (tblDum)...
1
by: Loreen | last post by:
I have been going through user groups and forums for the past 3 hours trying to figure out how to add "all" to my combo boxes. I've got two unbound comboboxes. Once only has one field...
3
by: Not Me | last post by:
Hi, Is there any criteria I can use in my where clause to say 'anything'? Maybe like the _ used in some languages? For my example, I want to use an inline-if, so if a checkbox is ticked I say...
3
by: tobhamlet | last post by:
If one is using a query as a Row Source on a Form, is there a way to set up a blank space, or to insert the word "ALL" in a combo box that represents ALL combo box row items. The scenario is as...
0
by: Greg Strong | last post by:
Hello All, In the past I've used a combo box with the 'row source' being an Access SQL union query to select "All" or 1 for only 1 criteria in a query. An example is as follows: SELECT 0 As...
3
by: google | last post by:
This is something I've done plenty of times in '97, but I can't seem to get it to work correctly in Access 2003. Say, for example, I have a form with an unbound combobox, the data source is a...
3
by: eskelies | last post by:
Good day all...I have a combo box that selects numbers (ie. 1,2,3, etc.). What I am looking for is the combo box to have an "ALL" selection. Right now this is what I have for my SQL code: SELECT...
3
Zwoker
by: Zwoker | last post by:
Hi Everyone, I have a query that uses criteria from combo boxes in the form that runs it. When I had only discrete values in the combo boxes that matched the data that was being queried, the...
1
by: StuartD | last post by:
I have a sub form that is populated based on the selection of a year from a combo box on the main form. I'm trying to add a second main form combo box for item category to further filter the sub...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.