473,386 Members | 1,710 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.

Count in a Text Box Control Source Property

Cro
Hello Access Developers,

I'd like to know if it is possible to perform a count in an expression
that defines a control source.

My report is based on a query. In my report, I want a text box to
display the number of times a certain value appears in a certain field
(i.e. perform a ‘count'). I will be doing this for many values in many
fields so do not wish to have scores of queries to build my report.

I have tried setting the control source property of the text box to
several expressions (none of which have worked):

SELECT Count(*) AS Counted FROM tableData WHERE
(tableData.field1="foo");
=(SELECT Count(*) AS Counted FROM tableData WHERE
(tableData.field1="foo");)
= Count ( [tableData]![field1] = "foo" )

MS Access' help file tells me that I can set the control source
property to an expression, which is a combination of operators, field
names, functions, literals, and constants that evaluates to a single
value. It also says that expressions can specify criteria (such as
Order Amount>10000) or perform calculations on field values (such as
Price*Quantity).).

Question 1) Is there an expression that will count the number of times
a certain value appears in a certain field in the underlying query the
report is based on?

Question 2) If so, how would it then be possible to add these values
up in another text box? For example, text box ‘A' and text box ‘B'
count the number of times the value "a" and "b" appear in ‘field1' of
the underlying table ‘tableData' respectively. Could then a third text
box ‘C' sum the values calculated for text box A and text box B?

Thank you greatly for your wisdom and expertise.

Regards,

Cro
Nov 13 '05 #1
5 18209
"Cro" <th*******@hotmail.com> wrote in message
news:24*************************@posting.google.co m...
Hello Access Developers,

I'd like to know if it is possible to perform a count in an expression
that defines a control source.

My report is based on a query. In my report, I want a text box to
display the number of times a certain value appears in a certain field
(i.e. perform a 'count'). I will be doing this for many values in many
fields so do not wish to have scores of queries to build my report.

I have tried setting the control source property of the text box to
several expressions (none of which have worked):

SELECT Count(*) AS Counted FROM tableData WHERE
(tableData.field1="foo");
=(SELECT Count(*) AS Counted FROM tableData WHERE
(tableData.field1="foo");)
= Count ( [tableData]![field1] = "foo" )


You can't use a sql string as the controlsource for a text box. Use a domain
aggregate function instead, e..g

=DCount("*", "tableData", "field1='foo'")
Nov 13 '05 #2
th*******@hotmail.com (Cro) wrote in
news:24*************************@posting.google.co m:
Hello Access Developers,

I'd like to know if it is possible to perform a count in an
expression that defines a control source.

My report is based on a query. In my report, I want a text box
to display the number of times a certain value appears in a
certain field (i.e. perform a ‘count'). I will be doing this
for many values in many fields so do not wish to have scores
of queries to build my report.

I have tried setting the control source property of the text
box to several expressions (none of which have worked):

SELECT Count(*) AS Counted FROM tableData WHERE
(tableData.field1="foo");
=(SELECT Count(*) AS Counted FROM tableData WHERE
(tableData.field1="foo");)
= Count ( [tableData]![field1] = "foo" )

MS Access' help file tells me that I can set the control
source property to an expression, which is a combination of
operators, field names, functions, literals, and constants
that evaluates to a single value. It also says that
expressions can specify criteria (such as Order Amount>10000)
or perform calculations on field values (such as
Price*Quantity).).

Question 1) Is there an expression that will count the number
of times a certain value appears in a certain field in the
underlying query the report is based on?

Question 2) If so, how would it then be possible to add these
values up in another text box? For example, text box ‘A' and
text box ‘B' count the number of times the value "a" and "b"
appear in ‘field1' of the underlying table ‘tableData'
respectively. Could then a third text box ‘C' sum the values
calculated for text box A and text box B?

Thank you greatly for your wisdom and expertise.

Regards,

Cro

Your expression is =DCount("tableData","[field1] = 'foo'")

two ways:
=DCount("tableData","[field1] = 'foo'") + DCount
("tableData","[field1] = 'bar'")

or

=field1.value+field2.value

The first works, the second sometimes works.
Bob Quintal
Nov 13 '05 #3

See my comments in line below....

On 24 Jun 2004 03:38:45 -0700, Cro wrote:
Hello Access Developers,

I'd like to know if it is possible to perform a count in an expression
that defines a control source.

My report is based on a query. In my report, I want a text box to
display the number of times a certain value appears in a certain field
(i.e. perform a ‘count'). I will be doing this for many values in many
fields so do not wish to have scores of queries to build my report.

I have tried setting the control source property of the text box to
several expressions (none of which have worked):

SELECT Count(*) AS Counted FROM tableData WHERE
(tableData.field1="foo");
=(SELECT Count(*) AS Counted FROM tableData WHERE
(tableData.field1="foo");)
= Count ( [tableData]![field1] = "foo" )
You CANNOT use SQL in a control source expression.
MS Access' help file tells me that I can set the control source
property to an expression, which is a combination of operators, field
names, functions, literals, and constants that evaluates to a single
value. It also says that expressions can specify criteria (such as
Order Amount>10000) or perform calculations on field values (such as
Price*Quantity).).
You can certainly use an expression... just not SQL.

Question 1) Is there an expression that will count the number of times
a certain value appears in a certain field in the underlying query the
report is based on?
If you wish to 'Count' the number of times a field ='foo' appears in
the report, then you could use:

=Sum(IIf([Fieldname] = "foo",1,0)

which adds 1 for each time it appears.

If you wish to count how many times a field = 'foo' appears in the
underlying table/query (which may be more than the number of times it
appears in the report due to additional filtering):

=DCount("*","[QueryName]","[FieldName] = 'foo'")

Note the use of double and single quotes in the where clause.
Question 2) If so, how would it then be possible to add these values
up in another text box? For example, text box ‘A' and text box ‘B'
count the number of times the value "a" and "b" appear in ‘field1' of
the underlying table ‘tableData' respectively. Could then a third text
box ‘C' sum the values calculated for text box A and text box B?
Repeat the individual calculations and add them up in any report
section except the Page Header/Footer sections.
Either:
=Sum(IIf([FieldName] = "foo" Or [FieldName] = "apples",1,0))

Note: The above will return just the count within the group if used in
a Group Header/Footer. It will return the count for all records if
used in the Report Header.Footer.

Or...

=DCount("*","[QueryName]","[FieldName] = 'foo'") +
DCount("*","[QueryName]","[FieldName] = 'apples'")

If you wanted to display the sum in the Page Header/Footer you would
then sum each individual criteria in the detail section (as in
Question 1 above), then in the Page Header/Footer you would use the
name of the control that did the calculation:

=[ControlA] + [ControlB] + [ControlC] + etc.
Thank you greatly for your wisdom and expertise.

Regards,

Cro


--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 13 '05 #4
Cro
Thank you John, Bob and fredg for you excellent answers. I will try
all these methods over the weekend and post back to let you know how I
got on.
Nov 13 '05 #5
Cro
th*******@hotmail.com (Cro) wrote in message news:<24**************************@posting.google. com>...
Thank you John, Bob and fredg for you excellent answers. I will try
all these methods over the weekend and post back to let you know how I
got on.


I was able to acheive exactly what I wanted using domain aggregate
functions so thank you all very much for your excellent answers.

Now that I'm aware of domain aggregate functions, I'll be using much
more of them.
Nov 13 '05 #6

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

Similar topics

6
by: Mark Lees | last post by:
I've created some fields that calculate future dates. The way they are set up they do not save to a table. This is the expression I used (=DateSerial(Year(),Month()+6,Day(). I placed it in the...
2
by: Gwin | last post by:
I am programming a client service dbase in access 2000 for a non-profit health clinic. I want to create a navigation menu that can show varying numbers of command buttons with varying captions,...
9
by: Jack | last post by:
In the control source of a textbox, is there a way to refer to a column of a combobox? For example: =.Column(2) Thanks, Jack
2
by: jerry.ranch | last post by:
I've been using row source with the QBE for my list and combo boxes..when would I use control source? jerry
2
by: HeroinNO.4 | last post by:
Hello everyone! Now the latest version of free count down timer source code is available in http://www.fillweb.com/countdown.htm, you can open it in IE and View->Source to see the latest version...
7
by: HeroinNO.4 | last post by:
Hello guys, free count down timer source code has updated to 06/11/27, you can copy the code below and save in a ".htm" file and run it in a browser support javascript 1.1 or later, or you can open...
4
by: Anja | last post by:
Hi everyone, I am trying to use the expression builder to create input to a control in an Access report. I have a table called Records and I want to select the minimum date for a record where...
2
by: vsteshenko | last post by:
Hello, This is my first post so I hope I'm doing this correctly. I am currently working on creating an order form for sales associates at my work to be used at conventions. I have a form with...
4
by: Lou O | last post by:
Is it possible to use the row (index) of a list box as control source Property for a text box? Example: Text1.ControlSource Property is set to "= List1.Column(0,2)" in design view. When I open...
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:
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
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: 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
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
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
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...

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.