473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Counting items in a report

prn
254 Expert 100+
Hi folks,

I've got another (inherited) puzzle that I don't understand.

A report that I need to modify contains a subreport that lists a variable number of items in its detail section and then has a footer which contains a count of those items. That is, the "detail" section of the main report consists of a page for each sub-category listing the items in that category and then includes a count of the items for that sub-category.

The way whoever (i.e., whichever of the half-dozen people it was) did that was to include with each detail item, an invisible textbox field (named COUNT with a "Control source" of "=1".

The puzzling part of this is that when I made the textbox visible, I found that the value in the boxes increased, so that rather than simply having a value of "1" in each line, the successive COUNT boxes were, indeed, a count. My anonymous predecessor then inserted the count into the footer as "=Sum([Count])/15" which, for reasons I fail to appreciate, actually appeared to work.

Unfortunately, I have to say "appeared to work" rather than "worked" because although it gave the correct total most of the time it occasionally geve the wrong total. I'm not sure why that is the case -- possibly a rounding error, but some of the totals are wrong. Frankly, I'm not even sure why most of them are right. What dividing by 15 should have to do with it makes no sense to me.

Anyway, my first real question is why "=1" as the control source for a textbox results in anything other than "1".

My next question is how to extract a useful value from the boxes. I have tried "=Max(Count)" but what I found is that the successive instances of this subreport all give the same total, whether or not that is the correct number for that page, e.g. all of them show "14" whether the real count for that page should be 14, 3, 22, or whatever. Using "=Last(COUNT)" does exactly the same, giving the same weird number that is the same for all of the pages. Using "=COUNT" is almost the same in that almost all of the pages get the same number as each other (10, which is not 14 and so is different from Max or Last), but a few pages get a different number (20). What I want to do is either to pull the last value of COUNT into the total box or else make all of the boxes have a value of "1" and then use "=Sum(COUNT)".

Any clues about what is going on, and/or what I am doing wrong would be gratefully appreciated.

Thanks,
Paul
Jan 16 '09 #1
4 2404
Stewart Ross
2,545 Expert Mod 2GB
Hi Paul. You have my sympathies here; I'd scrap the current approach, as the way this has been implemented so far is in my opinion too flawed to rescue.

The fundamental flaw is to try to add counts etc after the event using unbound textboxes - this is likely to rely on code behind the report's sections to set the textbox values. Such an approach is at best difficult to maintain; at worst it may not give accurate results at all. Since the actual values of the textboxes do not appear to match the control sources something must have changed them - I can only guess at this, but presumably as a result of on-format or on-print event code behind one or more of the report sections.

Unless code behind sections is carefully written it can result in errors as the sections are revisited during formatting etc, leading to repeated updates of the same value.

I would suggest that the simplest way to deal with this is not to waste time trying to maintain the unmaintainable. Instead, add computed fields to the query on which the subreport is based, so that something countable is available for each row of the base query. With such a computed field you can then use the normal report summing and counting to summarise the data without resorting to bespoke programming or using unbound textboxes.

A computed field for the base query could be based on a simple IIF, like this:

Expand|Select|Wrap|Line Numbers
  1. ThisIsAWidget: IIF([whatever makes it a widget] = [somecondition], 1, 0)
Then in the subreport you can use the normal sum and count facilities to summarise the values in the ThisIsAWidget fields and any others that you add.

Hope you resolve this one satisfactorily...

-Stewart
Jan 16 '09 #2
prn
254 Expert 100+
Thanks, Stewart.

I did wind up adding a field to the base query, but I just added a line to the SELECT:

1 as TICK

and then summed the ticks. It works essentially like the original should have worked, but in this case, the TICKs are all 1 instead of an increasing list and now the SUM actually works.

I still do not understand why an unbound control with a value of "=1" should have any value other than "1" but it did, so I solved it in the SQL and left myself with minimal rewriting.

Thanks,
Paul
Jan 20 '09 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi Paul. I think I may have a possible answer to the mystery of the incremented values - in a report you can set a control's Running Sum property to Over Group or Over All. Bet this being set was the reason for the auto increases on the unbound control. I have tried it out now myself and it increments the unbound control as you described.

Glad you found a suitable resolution which is far more transparent and very simple.

-Stewart
Jan 20 '09 #4
prn
254 Expert 100+
Thank You, Stewart!

Yes! I had not noticed the Running Sum property and had not been aware of it at all, but you're right. It was being incremented "Over Group" Whoever wrote this report obviously didn't understand it, either and then tried to work around it with quite buggy results. If that had been set to "No" the report would have been so much simpler.

I still don't understand how whoever it was got where they did, but at least one of the small mysteries is now cleared up.

Thanks a lot!

Paul
Jan 21 '09 #5

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

Similar topics

2
by: N. Graves | last post by:
I have a table with records of games played with a field for players name and another fields is a "WinorLose". One player may play several games to complete a match. I want my report to tell me...
3
by: Megan | last post by:
hi everybody- i'm having a counting problem i hope you guys and gals could give me some help with. i have a query that retrieves a bevy of information from several different tables. first let...
1
by: mjobrien | last post by:
Thanks for the hint Allen (see below). But I am already doing that count as total records read (5)in the report footer. That count is unduplicated for the record not for the field - student ID as...
2
by: Geir Baardsen | last post by:
Hi! From a listbox I'd like to send only selected items to a report. Items will include: OrderNr,Date,EmployeeNr from tblOrders ZipCode,City from tblZipCodes Name,Adr,ZipID from...
18
by: ChadDiesel | last post by:
I appreciate the help on this group. I know I've posted a lot here the last couple of weeks, but I was thrown into a database project at my work with very little Access experience. No other...
3
by: Miguel | last post by:
I have a parameter query to filter by date from which I run a report. I need to be able to count the number of times a particular product or error type appears after the report is run from the...
14
by: Dan | last post by:
Is this discouraged?: for line in open(filename): <do something with line> That is, should I do this instead?: fileptr = open(filename) for line in fileptr: <do something with line>
1
by: RussCRM | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
1
by: elgoober | last post by:
Hi I have a report that looks at no of products sold by customer by range. The report groups on the range and I'm interested in counting the number of companies buying the range. Since they...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.