Question : How could you convert a table of records into another table of the records as details records with subtotals and totals using an ADP file ?

I am developing an Access application in Access 2003 using Access as the front end and SQL Server as the back end database. I run a stored procedure that has a result set of approximately 43,000 records that are populated into a table named tblDtlBranchAll.

Could the following sample records, which exist in table tblDtlBranchAll be manipulated via a stored procedure or Query to create sorted records with totals and subtotals so that the result set would appear like the output below the dotted lines into another table which I could then be export into an Excel file using DoCmd.Transferspreadsheet ? My users like to see all their output in Excel files since they are Accountants.
 
Branch             Customer Number    Date Range           Property Type       Value
004                   111333111              0 To 6 Months       STOCKS                21.00
004                   111333111              0 To 6 Months       BONDS                  11.25
004                   888333111              0 To 6 Months       STOCKS                  8.00
004                   888333111              0 To 6 Months       BONDS                  12.25
004                   922111111              6 To 12 Months     STOCKS                44.00
004                   922111111              6 To 12 Months     BONDS                  22.25

-------------------------------------------------------------------------------------------------------------

The report takes the table records and performs subtotals and totals on the records as follows:
How can I get the results as follows with the subtotals and totals into an Excel file ?
Can a query be used if I am working with an ADP type file ?
The records are sorted by Customer Number within Date Range.


Branch              Customer Number   Date Range           Property Type       Value
004                   111333111              0 To 6 Months       STOCKS                21.00
004                   111333111              0 To 6 Months       BONDS                  11.25
Sub Total                                                                                                               33.25

004                   888333111              0 To 6 Months       STOCKS                 8.00
004                   888333111              0 To 6 Months       BONDS                 12.25
Sub Total                                                                                                               20.25

004                   922111111              6 To 12 Months     STOCKS                44.00
004                   922111111              6 To 12 Months     BONDS                  22.25
Sub Total                                                                                                               66.25
Total                                                                                                                     119.75

Answer : How could you convert a table of records into another table of the records as details records with subtotals and totals using an ADP file ?

zimmer9,

In the attached file, press the button to get the results.

Hope it helps

Patrick
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
Sub calc_subtotals()
Dim str As String
Dim lastrow As Long
Dim i As Long
Dim rng As Range
Dim celle As Range
Dim str1 As String
Dim str2 As String
Dim rowe As Long
Dim temp As Double
 
Application.ScreenUpdating = False
 
rowe = 2
str1 = "A"
str2 = "E"
With Sheets("Sheet1")
    Set rng = Range(.Cells(rowe, str1), .Cells(.Cells.Rows.Count, str2).End(xlUp))
End With
 
rng.Sort Key1:=Range("C2"), Order1:=xlAscending, Key2:=Range("B2") _
        , Order2:=xlAscending, Key3:=Range("E2"), Order3:=xlAscending, Header:= _
        xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
        xlSortNormal
 
str = "B"
With Sheets("Sheet1")
    lastrow = .Cells(.Cells.Rows.Count, str).End(xlUp).Offset(1, 0).Row
 
For i = lastrow To 3 Step -1
    If .Cells(i, "B") <> .Cells(i - 1, "B") Then
        .Rows(i).Insert Shift:=xlDown
    End If
Next i
 
str = "B"
lastrow = .Cells(.Cells.Rows.Count, str).End(xlUp).Offset(1, 0).Row
 
temp = 0
For i = 2 To lastrow
    temp = temp + Cells(i, 5)
    If Cells(i, 5) = "" Then
        Cells(i, 6) = temp
        temp = 0
        Cells(i, 1) = "Sub-total"
    End If
Next i
 
End With
 
Columns("F:F").NumberFormat = "#,##0.00"
 
Application.ScreenUpdating = True
 
End Sub
Open in New Window Select All
 
 
Random Solutions  
 
programming4us programming4us