Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB code to initialize GBL_Sum or ivalue ?? 1

Status
Not open for further replies.

hefly

Technical User
Joined
Feb 6, 2008
Messages
134
Location
US
Blue Claw publishes VB code on their website that does a running sum.

Unfortunately, the running sum is not set to zero when the code runs. So if you happen to run the code twice, the new output increments from the last value of the previous run.

How do you initialize the code for each run?

Thanks

Hefly

Code:
Option Compare Database

Global GBL_Sum As Double 
Public Function Init_Globals()
GBL_Sum = 0
End Function


Public Function global_add(ivalue) As Double
GBL_Sum = GBL_Sum + ivalue
global_add = GBL_Sum
End Function

Query
Code:
SELECT tbl_Nets, Global_Add ([NetAmt]) AS [Running Sum]
INTO T_Query_Results
FROM tbl_Nets;

 
SELECT tbl_Nets, Global_Add ([NetAmt]) AS [Running Sum], Init_Globals() AS dummy
INTO T_Query_Results
FROM tbl_Nets

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV. Thanks so very much. That made the query work.
I would like to delete this post. Do you know how? Thanks.
Hefly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top