Sum Currency of line items - listbox (1 Viewer)

Shaunk23

Registered User.
Local time
Yesterday, 20:36
Joined
Mar 15, 2012
Messages
118
I have a listbox that can have anywhere from 1 entry to probably 20 entries at a time. Its for a quoting database.. Each quote can have multiple line items.. This list shows the line items.. IE: Trucking / Ocean Freight / Customs Clearance etc..

The list has columns - ID / Description of Line Item / Cost / Sell

I have three text boxes above that.. I need to calculate the totals into those textboxes. What is the easiest and most efficient way to do this.. remember they are in currency. Is there a dsum or do i have to create a loop ???
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:36
Joined
Aug 30, 2003
Messages
36,140
I assume you mean you want to sum the selected items? This type of thing:

Code:
  Dim varItem                 As Variant
  Dim ctl                     As Control
  Dim curTotal                As Currency

  On Error GoTo ErrorHandler

  Set ctl = Me.lstPayments

  curTotal = 0

  For Each varItem In ctl.ItemsSelected
    curTotal = curTotal + ctl.Column(5, varItem)
  Next varItem
  Me.txtTotalPayments = curTotal

In the after update event of the listbox.
 

Shaunk23

Registered User.
Local time
Yesterday, 20:36
Joined
Mar 15, 2012
Messages
118
Hello - No i need to sum the entire listbox.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 17:36
Joined
Aug 30, 2003
Messages
36,140
Something like this:

Code:
  Dim x                       As Integer
  Dim curAmount               As Currency
  For x = IIf(Me.lstPayments.ColumnHeads, 1, 0) To Me.lstPayments.ListCount
    curAmount = curAmount + Nz(Me.lstPayments.Column(5, x), 0)
  Next x
  MsgBox curAmount
 

Users who are viewing this thread

Top Bottom