lightcross
asked on
listbox itemselected code
Hello,
I cant figure what is wrong with my code here. What is supposed to happen is after a user updates the listbox by either highlighting it or un-highlighting it, a textbox will then be updated with a "total" from column 1. what is actually happening is... if there are 3 items selected and there column 2 value is 2, 6, 20 the final result will be "6". what is happening is that it is only getting the first value and adding itself once for every item selected. so another example would be 10, 8, 25 my final value would be 30. when it should be 43.
Private Sub lstDieCount_AfterUpdate()
Dim varItm As Variant
Dim varDieNumber As Variant
Dim varDieNumberAdd As Variant
varDieNumber = 0
varDieNumberAdd = 0
'here i would like to add the numbers from column 1 for every item selected.
For Each varItm In Me.lstDieCount.ItemsSelect ed
varDieNumberAdd = Me.lstDieCount.Column(1) ' Column 1 contains a number value. could be any number.
varDieNumber = varDieNumber + varDieNumberAdd ' this code is supposed to add the number value
Next
Me.tbDieCount = varDieNumber 'this end result should report a total number.
End Sub
I cant figure what is wrong with my code here. What is supposed to happen is after a user updates the listbox by either highlighting it or un-highlighting it, a textbox will then be updated with a "total" from column 1. what is actually happening is... if there are 3 items selected and there column 2 value is 2, 6, 20 the final result will be "6". what is happening is that it is only getting the first value and adding itself once for every item selected. so another example would be 10, 8, 25 my final value would be 30. when it should be 43.
Private Sub lstDieCount_AfterUpdate()
Dim varItm As Variant
Dim varDieNumber As Variant
Dim varDieNumberAdd As Variant
varDieNumber = 0
varDieNumberAdd = 0
'here i would like to add the numbers from column 1 for every item selected.
For Each varItm In Me.lstDieCount.ItemsSelect
varDieNumberAdd = Me.lstDieCount.Column(1) ' Column 1 contains a number value. could be any number.
varDieNumber = varDieNumber + varDieNumberAdd ' this code is supposed to add the number value
Next
Me.tbDieCount = varDieNumber 'this end result should report a total number.
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Weird.
I distinctly remember writing one more comment. Something to the effect of "this is considered illogical" ( col,row instead of row,col ) ... I must have writting it and never clicked [Submit]!
Anyway, glad to help and good luck with your project!
(°v°)
I distinctly remember writing one more comment. Something to the effect of "this is considered illogical" ( col,row instead of row,col ) ... I must have writting it and never clicked [Submit]!
Anyway, glad to help and good luck with your project!
(°v°)
ASKER
.... = Me.lstDieCount.Column(varI
FYI, I drove myself nuts on this one for at least a couple hours!