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?
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?
Re: Sum data in MSFlexgrid.
2 grids? Sounds unreasonable.
What's your sql look like? Maybe we can tune it for you if you post it...
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"
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