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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox sum of columnt (thread702-673191) 1

Status
Not open for further replies.

Grey0ne

Technical User
May 22, 2006
12
0
0
EE
Hi,
I do have a question how to make a sum in textbox on form with listbox by a column,
in these thread found an advice but its not working for me somehow :(
listbox name is lstOrders, column for which sum is needed is 6, textboxname - tboListSum

in source code of textbox - tboListSum=sumListboxColumn([lstOrders];6)
and the function is the same as in old thread -
Public Function sumListboxColumn(lstbox As Control, columnNumber As Integer) As Integer
On Error GoTo Err_sumListboxColumn
Dim counter As Integer
Dim total As Integer
total = 0
For counter = 0 To lstbox.ListCount - 1
total = total + lstbox.Column(columnNumber, counter)
Next counter
Exit_sumListboxColumn:
sumListboxColumn = total
Exit Function
Err_sumListboxColumn:
MsgBox Err.Description
Resume Exit_sumListboxColumn
End Function


Can anyone explain me why its not working? got a #Name? error...
 
How are ya Grey0ne . . .
[ol][li]Replace lstbox with Me!lstOrders and sumListboxColumn with Me!tboListSum[/li]
[li]Check the Name property of the above controls to be sure.[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
Have you tried this as ControlSource ?
=sumListboxColumn([lstOrders];6)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
2PHV
yeap, but when trying to open form i do get this error
Invalid Use or Null

When click on Ok (the only available button) receive a 0 in textbox

2TheAceMan1
in here?
tboListSum=sumListboxColumn([lstOrders];6)?
nope, Name property is the same, but still #Name? err
 
You may try the following in your function:
total = total + Nz(lstbox.Column(columnNumber, counter), 0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV
thanks, helped, now at least i know it wasn't summing anything, got a "0" )

ok, question is if a rowsorce columns as follows
Tellimus(number); Klient(text); Maksja(text); Kuupaev(date); Pank(text); Kokku(currency)
and i want sum for "kokku" column - it is a 6 one?
and if itis a currency do i need to change anything in the VBA code?
 
because i dont understand what it is summarizing then, if it gets a "0" as a rezult
 
Here the column numbers:[tt]
Tellimus; Klient; Maksja; Kuupaev; Pank; Kokku
0 1 2 3 4 [!]5[/!][/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top