I am trying to create a dynamic function that will calculate the sum of a column of a listbox.
When calling the function I would like to specify the form, the listbox and the column.
Somehow the form name and listbox name are not coming through.
Do you have any suggestions?
To call the function, I use:
When calling the function I would like to specify the form, the listbox and the column.
Somehow the form name and listbox name are not coming through.
Do you have any suggestions?
Code:
Function GetListBoxSum(frmName As Form, lstName As ListBox, intColumn As Integer) As Currency
Dim i As Integer
Dim j As Integer
Dim ctl As Control
Set ctl = Forms![frmName]![lstName]
j = ctl.ListCount - 1
GetListBoxSum = 0
For i = 1 To j
GetListBoxSum = GetListBoxSum + ctl.Column(intColumn, i)
Next i
End Function
To call the function, I use:
Code:
GetListBoxSum(Me.Form, Me.lstPurchasesResult, 6)