PDA

View Full Version : [Access] Running Sum Problem


TheShaner
02-27-2006, 06:13 PM
Alright, I've run into a strange problem in Access that does seem to make sense, yet strange in the sense that it only acts up at certain times; the pattern of which I can't figure out. Nonetheless, I still need to figure out a solution as if it happened all the time.

Ok, here we go:

I have a report that is broken down into a couple groups and a details section, which contains the records from a query I have. Some textboxes are controlled be their control source, but most are figured out from forumlas inside the VB code in the detail_print sub.

Along with these are running sum textboxes that sum over the group and are hidden. These running sums tally up the sums of certain textboxes so that when it's time to print the group, all i have to do is display the final value of the running sum that is hidden in the details section.

It seemed to work fine until recently. I noticed that there were a couple instances where ALL the running sums in the detail section computed BEFORE the formulas in the VB code were set, which then took their values from the last record of the previous group. I could not find any pattern, however, for when the running sums would compute first, except that the two instances were where there was only one record in the group. As soon as I added another record in the group, the running sums would compute after the forumas were figured out. But I still say no pattern to it, cuz there were previous groups with only one record that worked ok.

Anyway, I was able to correct one of the running sums by placing the VB code formula into the control source. With this set up, the textbox computed before the running sum, but all the others that had the formulas computed in the VB code in the detail_print sub, the running sums computer first.

The problem is that I can't do this for all the textboxes. I can't put all the formulas in the record source. There are some that must be computed by looking up values in other tables and such and then a formula is applied.

How can I be sure that the VB code formulas compute first before the running sums? Why would this happen only when there is only 1 record in the group, but only happen sometimes? I must compute the formulas in detail_print because detail_format will run more than once. I've been through a lot of problems and weird Access quirks, but this one baffles me the most. I consider myself fairly adept in handling Access and VB, but I must admit that this problem has me really stumped.

Thanks for any guidance anyone can offer me!

-Shane

TheShaner
02-27-2006, 10:42 PM
Well, I doubt anyone has any answers. It's a strange problem and plus not many people deal with Access. I seem to be the only one, hehe.

Anyway, my solution was just moving all my formulas from the detail_print sub to the detail_format sub. After analyzing my code, I realized that if detail_format is run more than once, it'd all just be redone instead of anything adding up from previous executions.

Detail_format always runs before detail_print, which is about the time the running sums execute, so all my formulas are done before the running sums start grabbing their values from the textboxes.

So all works fine now, although it certainly didn't answer my question to why that happened. Oh well.

-Shane