Code to count records

Thread Sidebar

Chris:
Attitude given is from attitude received. Respect is earned not awarded. In the past I have been mistaken and I do appreciate when this is pointed out as one is never to old or young to learn from their mistakes. But, as there are different ways to solve this coding problem, there are also different ways to respond to members. If you do so disrespectfully, you can't expect someone to suck it in and not respond. If it were pat, roy, or even ghudson who I regurlarly interact with in other threads, I would think nothing of it.. I understand where they're coming from. But you, my friend, I don't know who you are.


Roy:
As with many other posts I agree with you. A Long may be more suitable. However, I like to cut corners and reduce memory used. Additionally, realize that my problem wasn't Chris's information, but it had more to do with how he responded.

My naming convention was more focused on what the value of the DCount() represented. It represented a count of all the records returned by the query. So I said call it intRcdCount. The focus wasn't on "int", which was suitable since the variable I used was an integer, but it was more focused on what the number represents.

Imagine if your DCount() took in a parameter longer then just "*"... or even imagine you dont understand what DCount() does. Now you're a person that comes into someone else's code and sees it in an IF statement. You have to look it up and see what it does..blah blah blah. If you had nRcdCount... you would notice that it just returned the number of records. Saving you time to actually go in and look up what a foreign function does.

I try not only to address the problem, but provide a better coding environment overall. Furthermore, I am not 40-50 I am in my 20's and come from programming C, where integers flow like water (hence when in doubt, this is my default case :)). Finally, as I may have said, I don't regularly use the DCount() I have my own convention of solving my solutions and it wasn't until lately that I've been testing which ones are more efficient in terms of speed and memory usage.


Regarding the code:
I also use the ((not rs.bof) and (not rs.eof)), however my code does:

If Not (rs.BOF And rs.EOF) Then

This throws out the "not" redundancy and is easier to read. I didn't originally post it because this is more of an error checking mechanism. The .movelast was important to include because if you didn't have it in there .RecordCount would still return a value, and the program would think nothing was wrong. I also inclue a .movefirst just to set the pointer back to the first record.
 
Well, I never thought counting records was such an interesting topic!!!

Have we all forgot about the overhead of domain aggregate functions?

If you guys (modest etc) are so experienced, should you not be attempting to give the pros and cons of methods when suggesting them, rather than preaching your own preferred ways?
 
Now that seems like a reasonable idea, cut code, stay in the black and out of the green. ;)
 
: agreed, though i never claimed to be so experienced. i'm always open to suggestions, hence the name (chris). i just like getting the job done :) also, we've gotten off topic, any non-code related issues should be settled in private from this point forward - i hope you all agree.

so whether you use dcount(), or recordset/clone, or even whether you use a count() from within a query; there are many ways to get the record count.

hope this thread was useful to whomever might need it
 
Last edited:
Hey Modest et al. So here it is 9 1/2 years later and your answer made my day -- thanks for taking the time to be so explicit and clear and for giving specific examples.
 

Users who are viewing this thread

Back
Top Bottom