|
|
 |
| Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

June 29th, 2009, 08:53 PM
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How to count negative numbers
Hi,
I have a report like this:
Avg Max Min Deviation Sample size
10 25 5 2 33
12 23 6 -1 35
13 18 8 3 40
14 14 7 -2 30
I am trying to write an expression that counts the negative numbers of the Deviation field. There will be a text box added right under the Deviation field. How can I count the negative numbers in the Deviation field? Thanks...
|

July 1st, 2009, 12:07 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,114
Thanks: 2
Thanked 4 Times in 4 Posts
|
|
You can use a DCount function on the record source... something like
=DCount("[Deviation]", "Table Name", "[Deviation] < 0")
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division
|

July 1st, 2009, 02:45 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,060
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Do you mean Sum the negative numbers? Or sum the negative numbers with the positive? Or sum the negative numbers AS positive numbers along with the positive, etc?
I am assuming this is on a report.
Put a text box on the group footer, or footer of the report, and then just type in =Sum([Deviation]) to get that sum.
If you want the negatives as positive, and the positive, you can do: =Sum(Abs([Deviation]))
You can also put the text box on the footer or header (group or report) and put code on the On Format event for that section to create your equation and put the result in the text box, etc.
Did any of that help?
__________________
mmcdonal
Look it up at: http://wrox.books24x7.com
|

July 1st, 2009, 07:14 PM
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Thanks for your help. I actually wanted to sum the negative numbers of the deviation field.
|

July 2nd, 2009, 08:22 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,060
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
If this were on a report, which I am assuming, then I would do this:
Put a text box on the report header or footer, then put this code in the text box:
Code:
=Sum(IIf([Deviation]<0,[Deviation],0))
What this does is Sum the Deviation values if they are less than 0, else it sums a zero.
So for this data:
Text Deviation
Row1 -1
Row2 -2
Row3 -5
Row4 6
Row5 7
The textbox returns -8.
Is that what you want?
__________________
mmcdonal
Look it up at: http://wrox.books24x7.com
Last edited by mmcdonal : July 2nd, 2009 at 08:23 AM.
Reason: add mark up
|

July 2nd, 2009, 02:49 PM
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hey, it worked! Thank you very much for your help. I really appreciate it.
I have one more question. How do I link numbers in 2 reports? For example, I have 2 reports Deviation and Summary. Deviation report has a st dev field. How can I link a st dev number from this report into the Summary report?
|

July 6th, 2009, 09:21 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,060
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
The very simplest way is to open the other report as acHidden, and then take the values from the report control. Make sure the On Close event of your visible report closes the other report. I would use 2 copies of each report: Deviation, Deviation_Hidden, Numbers, Numbers_Hidden, just so there is no overlapping code.
The most elegant way to do this is to create public function in a module that gathers that data regardless of where the call is from. So the control on the Numbers report would be: fnDeviation(), and vice versa.
I always use ADO since I always do Access / SQL, so maybe Greg's code would work best for this.
Did that help?
__________________
mmcdonal
Look it up at: http://wrox.books24x7.com
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |