473,657 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running Sum in a Query (Module Help)

46 New Member
Hello,

I have searched for help on this and have not been successful in finding an answer to my particular problem.

I am trying to compute a running sum of sales in a query.

Here is the query output as of now:



The "gross" column is the amount of sales in that particular month. I would like the "progress" field to be the running sum.

As you can see, I've made some progress (using the Microsoft Northwind database sample and this link: http://support.microsoft.com/kb/205183

However, notice how the last cell (for March) goes back to $152,000 instead of adding to the prior total.

Also, I would like the module to maintain the current total for the rest of the year. That is, for the months of April through September, I'd like to current progress to appear (about $185mm).

Here is the module code I am using:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Function bbrunsum(production_month As Date, gross_amount As Currency) As Long
  5.     Static pro_month As Date
  6.     Static gross As Currency
  7.  
  8.     If pro_month = production_month Then
  9.         pro_month = production_month
  10.         gross = gross_amount
  11.     Else
  12.         gross = gross + gross_amount
  13.     End If
  14.     bbrunsum = gross
  15. End Function
Any help is very much appreciated.

Thanks,

Brian
Jan 5 '08 #1
1 2747
PianoMan64
374 Recognized Expert Contributor
Hey Brian,

What is it that you are passing to the variable (Pro_Month), is it the date that is in the table labeled Pro_Month?

If so, what the original document was referring too is, that it is an numeric value that is passed that gives the current block or group a unique value that is used to do the running sum on. If you want to define it per ficial year, then you would pass it a same numeric value for the whole ficial year. i.e. (Format([pro_month]+Month(3),"yyyy "). When your new ficial years starts.

Make changes to the code that are in BOLD and that should take care of having the running total displayed.

Option Compare Database
Option Explicit

Function bbrunsum(produc tion_month As Long, gross_amount As Currency) As Long
Static pro_month As Long
Static gross As Currency

If pro_month = production_mont h Then
pro_month = production_mont h
gross = gross_amount
Else
gross = gross + NZ(gross_amount,0)
End If
bbrunsum = gross
End Function



Example:

FY2008 is something that is calculated on the Query, I'm assuming. If you convert that to a number and then pass that to the routine, and change the Date definition back to Long, then that should take care of how the items are grouped as well as when it knows to reset the running sum for the following ficial year.

If the item in March keeps reseting, then you need to look at the data for that month and see if there is something that may have an incorrect year or something that is triggering the reset of the variable that is storing the sum total that is currently running.

Hope that helps,

Joe P.
Jan 5 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2490
by: none | last post by:
Hi. I'm implementing a web deployment using 9i. I have a table for STOCK, which has one or more PURCHASES, which have one or more PURCHASE_ITEMS. When a purchase item is INSERTED, I'd like the web module component to update the relevant grandparent record of STOCK, and when UPDATED, to remember the previous level and adjust accordingly. I'm sure that this can probably be done in PL/SQL, but don't have a clue how - all books and...
7
6922
by: Ross Presser | last post by:
OK, I've been researching this problem and can't find a definitive answer yet. The situation is one that seems to have come up a few times to different folks. I am writing an application that will function as a windows service and will also present a GUI to the user. I don't want "Interact with desktop"; I want the same exe to run as a normal non-interactive service when started properly by the service control manager, or instead to run...
8
17491
by: Dalan | last post by:
Please help - just take a quick look at the function code below. It probably just needs some minor tweaking. The function module is based on an intermediate query to provide a group record total from a subform that is posted to a field on the main form. "Everything seems to work fine" except that I consistently receive an error everytime I attempt to create a new record on the main form. However, there are no errors received when...
7
1827
by: Peter Bailey | last post by:
I have a query that returns weekly enrollments: Qrygetweeklycountofdosmoduleenrollments Week Commencing Week Ending Total Bookings 02/04/2004 02/04/2004 0 05/04/2004 09/04/2004 0 12/04/2004 16/04/2004 1 19/04/2004 23/04/2004 2 26/04/2004 30/04/2004 1 03/05/2004 07/05/2004 1
2
228
by: Peter Bailey | last post by:
I have a query that returns the following: Qrygetgroupsofstartdates DosmID MODULE Name From To 242 M9S 01/09/2003 05/09/2003 242 M9S 01/09/2003 12/09/2003 242 M9S 01/09/2003 16/09/2003 242 M9S 01/09/2003 19/09/2003 242 M9S 01/09/2003 26/09/2003 242 M9S 03/09/2003 26/09/2003 242 M9S 08/09/2003 19/09/2003
2
5775
by: Smartin | last post by:
Using Access 97 I am trying to create a form that allows for user entry of search terms and displays a table of results. I thought I could accomplish this using a subform but it isn't quite doing what I want it to do. What I have so far: Fields to enter search terms Subform bound to a query
0
2206
by: schan | last post by:
Hi there, I was wondering if someone could shed some light on a problem I have no idea on how to fix. I created an Excel Add-In that uses an ADO connection to an Access database on a file server, which in turn has its tables linked to an Oracle back-end. I'm pretty sure I can take out Access as the middleman by just querying against the Oracle database, but that's not my question.
7
1723
by: funfair | last post by:
hi,every one im facing a problem in running access it's about 25 tables 80 forms 46 query (5 append query ,1 update query ,2 delete query ) 60 reports 4 modules after 7 months of perfect working in access 2003 around 8users working in it .i was working with these users in my sharing folder which i know that may corrupt the whole application but from one week i transfer it
1
989
by: mountainbig | last post by:
Greetings! I have a table for for sales order with module information related to sales. i have a Module table with a list of modules. i am trying to create a query to pull all the sales accounts with modules that do not exist in the modules table. and i need the following columns pulled in the results AccountID AccountName SalesOrderID SalesLineID PartNumber PartNumberDescription Module
0
8402
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8829
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8608
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5633
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.