addition in listbox

B

billypit786

List is like this in Listbox(Me.PalletIDOrTrackingNo_ListBox)

LONO----|PalletNo|Description-----------|BatchNO--|CRTN|Pcs|Total|
Remain|Location
->1------|2---------|3---------------------------------|
4---------------|5----|6----|7-----|8------|9--------
->7807 | 21102 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 |
256BA
->7807 | 21103 | DKNY BE DELICIOUS | 79658BV3 | 30 | 10 | 300 | 300 |
256BB
->7807 | 21104 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 |
256BA
->7808 | 21105 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 |
256BD
->7808 | 21106 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 |
256BD
->7807 | 21107 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 |
256BA
->7807 | 21108 | DKNY BE DELICIOUS | 79658BV1 | 20 | 10 | 200 | 200 |
256BA
->7808 | 21109 | DKNY BE DELICIOUS | 79658BV2 | 20 | 10 | 200 | 200 |
256BD

How can I add selected items from column 8(Remain)?
Like If I select first line then TotalRemain=200
then If I select 2nd line then TotalRemain=200+300=500
then If I select 3rd line then TotalRemain=200+300+200=700

then If I disselect 2nd line then TotalRemain=200+300+200-300=400


I am using this code but its not working properly

For Each var In Me.PalletIDOrTrackingNo_ListBox.ItemsSelected
Me.TotalRemain = Me.TotalReamin +
Me.PalletIDOrTrackingNo_ListBox.Column(8, var)
Next var

using this code things gone like this

Like If I selected first line then TotalRemain=200
then If I select 2nd line then TotalRemain=200+200+300=700 instead of
200+300=500
then If I select 3rd line then TotalRemain=200+200+300+300+200=1200
instead of 200+300+200=700

I don't get it why this is happening but I think its bcz I am using
FOR EACH.
can anyone help me?
 
J

Jim Bunton

Well I did somethiong like this recently

Dim slist As Control, Rowdex as Long

Set slist = Me.ListBoxName
For RowDex = 0 To slist.ListCount - 1
If slist.Selected(RowDex) Then
'do what's necessary like add the values of some column
end if
Next RowDex

I guess my code looks a bit old hat compared to yours but it works!
Afraid I haven't ever tried 'for each' !!
 
B

billypit786

this is mine code

For Each var In Me.PalletIDOrTrackingNo_ListBox.ItemsSelected
Me.TotalRemain = Me.TotalReamin +
Me.PalletIDOrTrackingNo_ListBox.Column(8, var)
Next var

and this is urs

Dim slist As Control, Rowdex As Long


Set slist = Me.PalletIDOrTrackingNo_Combo
For Rowdex = 0 To slist.ListCount - 1
If slist.Selected(Rowdex) Then
Me.extra8 = Me.PalletIDOrTrackingNo_Combo.Column(8, Rowdex)
Me.TotalQuantity1 = Me.extra8 +
Me.PalletIDOrTrackingNo_Combo.Column(8, Rowdex)
End If
Next Rowdex

both are doing the same thing and creating same problem.
thanks for ur reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top