Results 1 to 6 of 6

Thread: Sum data in MSFlexgrid.

  1. #1

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Sum data in MSFlexgrid.

    Hi everyone!!!

    I need help in summing these data by date.



    How do i do this using one MSFlexgrid? After summing it, the output should only have 3 rows.

    The expected output should be like this.

    261 | 5986.67 | $652.9091 | 700.44 | $84.0528 | 2/1/2011
    51 | 1959.09 | $201.2143 | 233.55 | $28.0260 | 2/2/2011
    220 | 4379.10 | $475.3718 | 199.66 | $23.9592 | 2/3/2011

    Any help is greatly appreciated.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Sum data in MSFlexgrid.

    You may loop threough date column and sum each column into variable; when date changes write it to grid, clear it and go to the next record...

    However, if you need sumarized data in the grid and data comes from database then why not use "Select Sum(some_field) ... Group By date_field" sql in the first place?

  3. #3

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Sum data in MSFlexgrid.

    Hi thanks for the input. I already wrote some codes but i got a alternate blank rows. What is the code for clearing the row?

    I cannot group by date field as my SQL is kinda complicated. Or what if i use a dummy MSflexgrid and put the values in there? What do you think?

  4. #4

  5. #5

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Sum data in MSFlexgrid.

    Here is my SQL.

    Code:
    mySQL = "Select ServiceDate,Sum(QuantityStat) as QuantityStat,Sum(QuantityNonStat) as QuantityNotStat,Sum(AmountStat) as AmountStat, " & _
                "Sum(AmountNonStat) as AmountNotStat,Sum(DocumentCount) as DocumentCount,CustomerID From View_DocumentBillingReport " & _
                "Where ServiceDate between '" & DTPicker1.Value & "' and '" & DTPicker2.Value & "' And CustomerID in ("135, 136, 137") Group by CustomerID,ServiceDate"

  6. #6

    Thread Starter
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Sum data in MSFlexgrid.

    here is my code snippet.

    is my logic correct?

    Code:
    Private Sub Command1_Click()
    Dim lngIndex As Long
    
    For lngIndex = 1 To MSFlexGrid1.Rows - 1
        With MSFlexGrid1
            If .TextMatrix(lngIndex, 6) = .TextMatrix(lngIndex + 1, 6) Then
               .TextMatrix(lngIndex, 1) = CLng(.TextMatrix(lngIndex, 1)) + CLng(.TextMatrix(lngIndex + 1, 1))
               .TextMatrix(lngIndex, 2) = CDbl(.TextMatrix(lngIndex, 2)) + CDbl(.TextMatrix(lngIndex + 1, 2))
               .TextMatrix(lngIndex, 3) = CDbl(.TextMatrix(lngIndex, 3)) + CDbl(.TextMatrix(lngIndex + 1, 3))
               .TextMatrix(lngIndex, 4) = CDbl(.TextMatrix(lngIndex, 4)) + CDbl(.TextMatrix(lngIndex + 1, 4))
               .TextMatrix(lngIndex, 5) = CDbl(.TextMatrix(lngIndex, 5)) + CDbl(.TextMatrix(lngIndex + 1, 5))
               .TextMatrix(lngIndex, 6) = .TextMatrix(lngIndex, 6)
            End If
        End With
    Next
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width