Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 29th, 2009, 07:53 PM
Registered User
 
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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...
Reply With Quote
  #2 (permalink)  
Old July 1st, 2009, 11:07 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
Reply With Quote
  #3 (permalink)  
Old July 1st, 2009, 01:45 PM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
Reply With Quote
  #4 (permalink)  
Old July 1st, 2009, 06:14 PM
Registered User
 
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Thanks for your help. I actually wanted to sum the negative numbers of the deviation field.
Reply With Quote
  #5 (permalink)  
Old July 2nd, 2009, 07:22 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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 07:23 AM.. Reason: add mark up
Reply With Quote
  #6 (permalink)  
Old July 2nd, 2009, 01:49 PM
Registered User
 
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
Reply With Quote
  #7 (permalink)  
Old July 6th, 2009, 08:21 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace the cells having negative value yogeshyl Excel VBA 4 April 29th, 2016 01:43 PM
Index was out of range. Must be non-negative raghavendra_das ASP.NET 2.0 Professional 0 July 24th, 2008 08:16 AM
Making a number negative Corey Access 1 February 2nd, 2007 11:48 AM
Index 0 is not non-negative! ktsis ASP.NET 1.0 and 1.1 Basics 1 July 5th, 2006 09:00 PM
negative number returned when subtracting gavmc Classic ASP Basics 2 November 29th, 2005 06:34 AM



All times are GMT -4. The time now is 08:32 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.