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.ItemsSelected
      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
LVL 2
lightcrossAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

harfangCommented:
Hello,

When you use .Column(), the first property is -- obviously -- the column number. However, it returns the value from the "selected" item, which happens to coincide with the first selection (the dotted line box). If you want to return the column 1 of another row, you need the second parameter:

    .Column( _column_ [, _row ] )

In other words:

    .... = Me.lstDieCount.Column(1, varItm)

Cheers!
(°v°)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lightcrossAuthor Commented:
Dang it!... I was trying it the other way around so I thought i was doing something wrong!  I was doing this:

  .... = Me.lstDieCount.Column(varItm, 1)

FYI, I drove myself nuts on this one for at least a couple hours!
harfangCommented:
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°)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.