472,356 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,356 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 6924

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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.