rjef
asked on
sub total listview
I vb6 how would i total these values in a listview? When po and item are equal and there is no serial value
PO | item | serial | Qty | tag |
111 | 11 | 110 | ||
111 | 11 | 110 | ||
123 | 1 | XXXX | 1 | XX |
123 | 1 | XXY | 1 | XY |
112 | 111 | 15 | ||
112 | 111 | 16 | ||
112 | 111 | 10 | ||
OUTPUT | ||||
PO | ITEM | SERAIAL | QTY | TAG |
111 | 11 | 220 | ||
123 | 1 | XXXX | 1 | XX |
123 | 1 | XXY | 1 | XY |
112 | 111 | 41 |
If you could attach a sample project it would save me some work.
Nevermind.
Did I do something similar to this for you a while back?
Add this code to a button on the form. Change line 11 to match the name of your listview and change line 58 to match the name of your command button.
Private Sub cmdSubtotal_Click()
Dim lngTotal As Long
Dim strOldPO As String
Dim strOldItem As String
Dim lngEntry As Long
Dim itmX As ListItem
Dim lngStart As Long
Dim lngDelete As Long
With lvSubTotal
strOldPO = .ListItems(.ListItems.Count)
strOldItem = .ListItems(.ListItems.Count).ListSubItems(1)
lngStart = .ListItems.Count
For lngEntry = .ListItems.Count To 1 Step -1
If strOldPO = .ListItems(lngEntry) Then
lngTotal = lngTotal + .ListItems(lngEntry).ListSubItems(3)
Else
' Remove the detail entries...
For lngDelete = lngStart To lngEntry + 1 Step -1
.ListItems.Remove lngDelete
Next
lngStart = .ListItems.Count
' ...and add a subtotal
Set itmX = .ListItems.Add(, , strOldPO)
itmX.SubItems(1) = strOldItem
itmX.SubItems(2) = ""
itmX.SubItems(3) = lngTotal
itmX.SubItems(4) = ""
Do Until .ListItems(lngEntry).ListSubItems(2) = ""
lngStart = lngStart - 1
lngEntry = lngEntry - 1
Loop
strOldPO = .ListItems(lngEntry)
strOldItem = .ListItems(lngEntry).ListSubItems(1)
lngTotal = 0
' This is needed because lngEnry is decremented when the loop starts over
lngEntry = lngEntry + 1
End If
' End If
Next
' Process the first PO
For lngDelete = lngStart To lngEntry + 1 Step -1
.ListItems.Remove lngDelete
Next
' The 1 here pleces the new entty at the top of the list
Set itmX = .ListItems.Add(1, , strOldPO)
itmX.SubItems(1) = strOldItem
itmX.SubItems(2) = ""
itmX.SubItems(3) = lngTotal
itmX.SubItems(4) = ""
End With
cmdSubTotal.Enabled = False
End Sub
ASKER
sort of but i could not compare
TestSubtotals.zip
TestSubtotals.zip
ASKER
If the last row is
PO item serial Qty tag
113 111 10
it messes up
PO item serial Qty tag
113 111 10
it messes up
I don't understand. Try this.
29201550.zip
29201550.zip
OK I attached my project before I saw your last post. I'll get back to you tomorrow.
ASKER
thanks
Is the "10" in that last row a Tag or is it a Qty?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Does my new code work for you?