Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 25th, 2007, 02:45 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 83
Thanks: 1
Thanked 0 Times in 0 Posts
Default Counting 'groups' of records in a report

Hiya folks!

I have a report that shows something like the following (note that some articles are repeated):

PRODUCT DATE QUANTITY SOLD
Coca Cola 01/07/07 10
Ginger Ale 01/07/07 20
Seven Up 01/07/07 15
Coca Cola 02/07/07 6
Seven Up 03/07/07 4
Fanta 04/07/07 13

I have another report that is exactly like this one, but using a PRODUCT_HEADER section in the report, I have managed to summarize the above in the following way:

PRODUCT QUANTITY SOLD
Coca Cola 16
Ginger Ale 20
Seven Up 19
Fanta 13

The problem I have is when I try to make a count of the different types of articles sold in the second one, it keeps giving me the total count of articles counted in the first one.

I should have a count of 4 in the summarized version, but it keeps giving me a result of 6. Is there any way to count the number of Product Groups (in this case 4) or to count unique values in the detail section of the report to give me a result of 4 instead of 6?

Thank you!
Reply With Quote
  #2 (permalink)  
Old July 25th, 2007, 05:01 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 83
Thanks: 1
Thanked 0 Times in 0 Posts
Default

The resulting value of 4 will then be used in a formula located in a separate field.

Reply With Quote
  #3 (permalink)  
Old July 25th, 2007, 10:55 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Okay, this works, but there may be more elegant way of doing it:

Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Dim sSQL As String
Dim rs As ADODB.Recordset
Public sValue As String

sSQL = "SELECT Count(Product) As PCount FROM qryYourReportQuery"
Set rs = New ADODB.Recordset
rs.Open sSQL, CurrentProject.Connection, adOpenStatic, adLockReadOnly
    sValue = rs("PCount")

Me.txtYourTextBox = sValue
rs.Close

End Sub


Now, I am not sure if the actual value in the text box will be available for your next formula, but the Public variable sValue WILL be. So try referring to the text box with something like:

=AVG([QtySold]/[txtYourTextBox])

And if that doesn't work, then do the calculation in code.

Did that help?

mmcdonal
Reply With Quote
  #4 (permalink)  
Old July 25th, 2007, 10:58 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry,

sSQL = "SELECT DISTINCT Count(Product) As PCount FROM qryYourReportQuery"

Alternatively, make a query off the query for your report that selects distinct count from your report query, and then just do this:

sSQL = "SELECT PCount FROM qrySelectDistinctQuery"




mmcdonal
Reply With Quote
  #5 (permalink)  
Old July 30th, 2007, 10:41 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 83
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hello again!

Thanks for your suggestion!

I am getting a compile error on this line of the code now:

rs As ADODB.Recordset

I guess I need to add this library, right? Can you tell me how to add libraries?

Thank you!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting Child Records BrianWren VB Databases Basics 1 June 2nd, 2008 04:32 PM
AbsolutePosition counting filtered records Brad_S VB Databases Basics 1 August 17th, 2006 04:24 AM
Counting records Jonas Access 4 August 4th, 2006 09:07 AM
A Cursor counting records chubnut SQL Server 2000 12 July 8th, 2004 01:58 PM
Grouping and Counting records Con Access VBA 1 September 17th, 2003 11:31 AM



All times are GMT -4. The time now is 12:15 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.