Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 20th, 2008, 12:42 PM
Registered User
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Subtotal fields

Hi,
  I need to figure out a way to subtotal records based on the following: I am coming up with the total, but it is placing the value at the end of the file. Code is below as well: Can someone please help.

Current Result:
CODE FIELD PRICE
ACQ_1 BOYDELL 20.00
ACQ_1 BOYDELL 100.00
ACQ_1 FULL 30.00
ACQ_2 BANKS 300.00
ACQ_2 BANKS 200.00
ACQ_3 FULLERTON 1000.00

End Result:

ACQ_1 BOYDELL 20.00
ACQ_1 BOYDELL 100.00
        SubTotal 120.00

ACQ_1 FULL 30.00
        SubTotal 30.00

ACQ_2 BANKS 300.00
ACQ_2 BANKS 200.00
        Subtotal 500.00
      .
      :

Private Sub Form_Open(Cancel As Integer)
Dim strFIELD As String
Dim rs As Recordset
Dim db As Database
Dim subTotBOYOIL As Double
Dim subTotBOYGAS As Double
Dim strSQL As String



Set db = CurrentDb

Set rs = db.OpenRecordset("tblGDP", dbOpenDynaset)


With rs
       Select Case rs![FIELD]
          Case "BOYDELL"
            rs.AddNew
            rs![RSV_CLASS] = "Sub Total"
            subTotBOYOIL = DSum("[NET RUN]", "tblGDP", "FIELD = 'BOYDELL'")
            subTotBOYGAS = DSum("[NET SAVE]", "tblGDP", "FIELD = 'BOYDELL'")
            rs![NET RUN] = subTotBOYOIL
            rs![NET OIL] = subTotBOYGAS
            rs.Update
          End Select
End With




rs.Close
db.Close

DoCmd.Close

End Sub





Jai
 
Old November 10th, 2008, 11:34 AM
Authorized User
 
Join Date: Jan 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
based on your last code,using the add new means u want the records to be appended 2 the last records,i will suggest u use a query that will retrieve the records,then make it a form's recordsource,this is an easier method.

my suggestion is based on the fact that from your code its obvious u are coming from the vb coding angle,if u are used to access vba code structures,this solution would have been easier.
alternatively u can create a command that sorts records based on a particular field and either attach it to your code so that it will run automatically orrattache it to a command button.
bye






Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtotal yogeshyl SQL Language 1 July 15th, 2008 02:16 PM
QUERY SUBTOTAL NEWAGE Access 2 November 8th, 2006 11:59 AM
percent of subtotal mtlpp Excel VBA 0 May 14th, 2005 10:09 AM
SubTotal Field geoffeg BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 September 23rd, 2004 06:20 PM
How to make subtotal of a column Sanjay Bajpai ASP.NET 1.0 and 1.1 Basics 7 September 14th, 2003 02:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.