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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to cound distinct fields in a report 3

Status
Not open for further replies.

Dumboy

Technical User
Feb 29, 2000
97
US
I'm back... this is a easy one for you guys..<br>
I need to count total PO Numbers in a report as a summary. some of the PO Numbers are duplicated and I need a count of the unique PO Numbers. I have tried the distinctcount thing at the field level but it keeps counting all of them.<br>
<br>
is it possible to do something like<br>
=Count([PONumber])<br>
in a unbound control box that will ignore duplicates...?<br>
<br>
Thanks..... <p>Dumboy..! Ouch..! ..my brain h<br><a href=mailto:spiderdesign@yahoo.com>spiderdesign@yahoo.com</a><br><a href= me... I need the money....! Pleaaaaaaseeeeeee....... !
 
OK this my seem goofy but it works<br>
Paste this function in a module<br>
-----------------------<br>
Public Function CountDistinct(Field)<br>
Dim db As Database, rst As Recordset, Temp As Single<br>
Set db = CurrentDb<br>
SQL = &quot;SELECT [PONumber] FROM YourTable GROUP BY [PONumber];&quot;<br>
Set rst = db.OpenRecordset(SQL)<br>
rst.MoveLast<br>
Temp = rst.RecordCount<br>
rst.Close<br>
db.Close<br>
CountDistinct = Temp<br>
End Function<br>
---------------<br>
<br>
In the &quot;SQL&quot; line change &quot;YourTable&quot; to your table<br>
and change the PONumber to what yours is if it's not POnumber.<br>
<br>
put this in your Textbox on your report to get the count<br>
<br>
=CountDistinct([PONumber])<br>
<br>
Thats it. <p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
Thanks DougP <br>
<br>
But I think I broke your code.... when I ran it... there is one of those horrible Windows messages with like a letter i but upside down (isn't that horrible...?) anyway it tells me<br>
i (upside down inside a little yellow triangle) Compile error<br>
Variable not defined<br>
<br>
Then I stared at the screen for half and hour and nothing else happend so I clicked the OK button and things got worse. It took me to another screen where amazingly the code you gave me was there....!<br>
<br>
There was also a yellow arrow -&gt; on the Public Function line (I did not put it there...)<br>
and the word SQL was highlited in blue.<br>
Public Function CountDistinct(Field)<br>
Dim db As Database, rst As Recordset, Temp As Single<br>
Set db = CurrentDb<br>
SQL = &quot;SELECT [PONumber] FROM YourTable GROUP BY [PONumber];&quot;<br>
Set rst = db.OpenRecordset(SQL)<br>
rst.MoveLast<br>
Temp = rst.RecordCount<br>
rst.Close<br>
db.Close<br>
CountDistinct = Temp<br>
End Function<br>
<br>
Since I have no clue as far as VB (which I think means VeryBright) I don't know how to define the variable. <br>
<br>
Man... can you fixed the code.... the other day I also broke the Internet.... that's another story...<br>
<br>
Thanks in advance for telling me how to fix my mess.....<br>
<br>
Regards,<br>
<br>
<p>Dumboy..! Ouch..! ..my brain h<br><a href=mailto:spiderdesign@yahoo.com>spiderdesign@yahoo.com</a><br><a href= > </a><br>
 
DougP.... I did change YOURTABLE with the name of my Table (actually a Query named GeneralReportQuery and I tried with and without the squeare brackets<br>
<br>
<p>Dumboy..! Ouch..! ..my brain h<br><a href=mailto:spiderdesign@yahoo.com>spiderdesign@yahoo.com</a><br><a href= > </a><br>
 
Dumboy, Love reading your posts! :)<br>
<br>
&quot;SQL&quot; is a reserved word. Access won't let you use it as a variable. Change &quot;SQL&quot; to &quot;strSQL&quot; and add the line below to the line immediately after the other one that starts with &quot;Dim&quot;:<br>
<br>
Dim strSQL as string<br>
<br>
That will define your variable for you. Good luck :)<br>
<br>

 
Sorry, typo: each Dim statement needs to be written on it's OWN line.
 
Hey.....! that worked.... Thanks Elizabeth..... Thanks DougP......!<br>
<br>
I got to start learning that VB thing......! please recomend any books or places to start from Zero...... also if you know about the reproductive habits of Neurons let me know... I need to populate my brain......! so many good neurons lost during my life...! and they don't grow on trees.....<br>
<br>
Regards, <p>Dumboy.! Ouch.! .my brain.....<br><a href=mailto:spiderdesign@yahoo.com>spiderdesign@yahoo.com</a><br><a href= > </a><br>It's hard to think with only one neuron......Ouch.....!....it hurts when I think......!
 
I bought this book and that book and got something out of one and something differnt out of another.<br>
Go to <A HREF=" TARGET="_new"> and type in &quot;Visual Basic&quot; there should be a ton of them.<br>
The best way to learn this stufff is using it.<br>
I have been a consultant, a Programmer, System Administrator<br>
Of course Elizabeth will attest to this we both have spent way too much time on our butts in front of a PC. I'm talking years <p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
Elizabeth ... Moi cheri...I'm using Access 97 sr2<br>
<br>
DougP... so, you want me to go to Amazon.com and buy all the books on Access...?<br>
do you think I'm made of dough....? (mmmhhh...! makes me think...you are probably associated with Amazon or at least stock holder, aren't you?)<br>
<br>
Isn't there a book (you can recommend) that has exercises like step by step little programming so I can get familiar with the VB thing.... once introduced to the concept I can branch out and let my neuron fly and express creativity by writing millions of code and VB programs...!<br>
<br>
I don't really want to.... but I'm sure there is a VB for Dummies book outhere... of course I will have to first read the VB for Idiots before I move up to the Dummies book...!<br>
<br>
Please let me know of any beginers resources... and again thanks for the help the code worked great.<br>
<br>
Regards<br>
<br>
<p>Dumboy.! Ouch.! .my brain.....<br><a href=mailto:spiderdesign@yahoo.com>spiderdesign@yahoo.com</a><br><a href= > </a><br>It's hard to think with only one neuron......Ouch.....!....it hurts when I think......!
 
You're right there is a book out there.<br>
NO I don't have any to recommend. I don't have any at all.<br>
I am looking at my book shelf right now.<br>
My recommendation was to go to Amazon.<br>
I have looked there and they do have a lot to choose from<br>
Pick one or two <br>
Or go to the book store and thumb through them which is better cause you can look at the way each Publisher presents the data.<br>
Everybody is different, some people like one book over another.<br>
The fastest way to get an answer Cheaply is to come here to Tek-Tips.<br>
The way I write a program so quickly is cause I have a folder on My server called &quot;DougCode&quot;. I can get to it from anywhere in the building.<br>
I put a shorcut to it in my &quot;Start&quot; button so I can open that folder in one second.<br>
I has code snippets in &quot;.txt&quot; files for things I've done over the years. There are 184 files in there right now.<br>
I don't have to remeber exact syntax.<br>
I just look in the folder and find one that might do what I need and copy and paste the code from it into my Access VBA code window.<br>
The text file also has instructions of particulars involved.<br>
<br>
So grab the code above here that works and create your own &quot;Dumboy-Code&quot; folder and be on your way.<br>
OK <p> DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br>
 
DougP... can I call you daddy.....?<br>
<br>
Thanks I have started my very own Dumboy code and I saved in a file called Dumboy code which I carry with me on a little floppy so I can access it anywhere in the building... sorry I don't have snippets... (I'm partial to dogs myself...) but once I learn more about VB I will get me a couple of those... (I imagine they get along with dogs just fine... right...?)<br>
<br>
Well thanks again.... and be sure.... I'll be back.... I wish somebody came up with a really simple, stupid question so I can help somebody for a change.....<br>
<br>
Later..... <p>Dumboy.! Ouch.! .my brain.....<br><a href=mailto:spiderdesign@yahoo.com>spiderdesign@yahoo.com</a><br><a href= > </a><br>It's hard to think with only one neuron......Ouch.....!....it hurts when I think......!
 
I'm just finishing up with a Microsoft Press CD called &quot;Mastering MS Access 2000 Programming&quot;. It is very basic, disappointingly so in my case as I thought I would be getting something more advanced. But it gets the main points across which can be fleshed out by other reference material. If there is a 97 version I would recommend that based on this. Do you have the MS reference documentation for Access 97? It is a pretty complete intro. But while you're at it why not try to talk your employer into buying you Access 2000 Developer edition with all of the documentation.
 
Thanks Elizabeth..... I'm already browsing books at Borders books.... dammed... bastards... only two days and I'm already addicted to their coffee..... I found a couple good books one from Waite... on VB... (I learned it stands for Visual Basic...!) <br>
<br>
Hey... if that Microsoft Press CD you have is bothering you... you can always send it to me...... :-] <br>
<br>
Thanks again... Later....... aaargggghhhh....oUcH...!....! <p>Dumboy.! Ouch.! .my brain.....<br><a href=mailto:spiderdesign@yahoo.com>spiderdesign@yahoo.com</a><br><a href= > </a><br>It's hard to think with only one neuron......Ouch.....!....it hurts when I think......!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top