Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding fields from listbox selection 1

Status
Not open for further replies.
Oct 23, 2002
110
US
I have a listbox on a form where users can select multiple records. I need to get 2 totals from the selections. I need to add the value of field A to put in Total A and field B to put in Total B. Total A and Total B are unbound textboxes that are on the same form as the listbox. Is there a simple way to do this?
 
Can you give an example of what you are talking about? I'm not sure I totally follow you. But you could do something like this, I think, as far as looping through the listbox:

Code:
Dim ctl as Control
Dim varItem as Variant

ctl = "YourListBoxName"
For Each varItem in ctl.Selected
   'Whatever you need to do with each item
Next varItem

Something like that, of course with your details filled in.
 
like KJV said, not sure if I follow completely?
what are field A & B, are they columns in your listboxes?

..if so, I would follow KJV's advice but,
KJV, correct me if I'm wrong, but I think you need
to declare ctl, as a listbox, not a control,
in order to utilize the "selected" property,
and as I was about to suggest, the "column" property.

Dim ctl as ListBox
Dim varItem as Variant

ctl = "YourListBoxName"


For Each varItem in ctl.Selected
TotalA = varItem.Column(1) + varItem.Column(3)
Next varItem
 
Anyway, I'd use this:
For Each varItem in ctl.[!]Items[/!]Selected

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the correction on the property there, PHV.
 
Field A is a column in my list box. Field B is also a column in my listbox.

Example:
I have selected two records in my listbox:
CustomerA AddressA RegionA TotalOrdersA TotalOrdersAmountA
CustomerX AddressX RegionX TotalOrdersX TotalOrdersAmountX

I need to add together TotalOrdersA and TotalOrdersX as well as TotalOrdersAmountA and TotalOrdersAmountX and place both of these sums in seperate textboxes on the form - TotalOrders and TotalOrdersAmount.
 
You may try something like this:
Me!TotalOrders = 0
Me!TotalOrdersAmount = 0
For Each varItem in Me![ListBox name].ItemsSelected
Me!TotalOrders = Me!TotalOrders + Me![ListBox name].Column(3, varItem)
Me!TotalOrdersAmount = Me!TotalOrdersAmount + Me![ListBox name].Column(4, varItem)
Next varItem

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV - This seems to have worked perfectly. Thank you very much for your help!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top