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

What is wrong with my Sum()??

Status
Not open for further replies.

SimonPGreen

IS-IT--Management
Mar 8, 2004
116
GB
Hi all,

Blatantly ripped off Getz, Litwin & Gilberts code to create a dynamic report base on a crosstab as follows:

Code:
Private Sub Report_Open(Cancel As Integer)
    Dim intColCount As Integer
    Dim intControlCount As Integer
    Dim i As Integer
    Dim strName As String
    On Error Resume Next
    
    Dim rst As adodb.Recordset
    Set rst = New adodb.Recordset
    rst.Open _
        Source:=Me.RecordSource, _
        ActiveConnection:=CurrentProject.Connection, _
        options:=adCmdTable
        
        intColCount = rst.Fields.Count
        intControlCount = Me.Detail.Controls.Count
        If intControlCount < intColCount Then
            intColCount = intControlCount
        End If
        
        For i = 1 To intColCount
            strName = rst.Fields(i - 1).Name
            Me.Controls("lblHeader" & i).Caption = strName
            Me.Controls("txtData" & i).ControlSource = strName
            'Me.Controls("txtSum" & i).ControlSource = "sum([" & strName & "])"
        Next i
        
        For i = intColCount + 1 To intControlCount
            Me.Controls("txtData" & i).Visible = False
            Me.Controls("lblHeader" & i).Visible = False
            Me.Controls("txtSum" & i).Visible = False
        Next i
    
        rst.Close
        
End Sub

Problem I have is that I cannot get the totals in the footer to work with the line

Code:
Me.Controls("txtSum" & i).ControlSource = "sum([" & strName & "])"

The field name is a date in the format 04/03/2007 etc however Jet complains that there is an extra ) in query expression '[sum([04/03/2007])]' for example.

Any ideas?

Simon
 
As much as I respect Getz and Litwin (we all happen to be in Redmond/Seattle at the moment) their solution is not very flexible. I prefer the solution at Check the Crosstab.mdb in the sample download.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks for the heads up guys - I will check out the alternative solution today.

I'm new to this and what I am actually trying to do is create a sum at the report footer of all the values falling under the same date?

Regards,

Simon
 
If you column heading from the crosstab is a date then read the FAQ in this forum faq703-5466.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top