summing a field - error

  • Thread starter Thread starter jenn
  • Start date Start date
J

jenn

i'm receiving the following error "argument not optional"
on my statement that reads:
curCheckReqTotal = dsum(lstboxCheckRequest.Column(7))

Does anyone know why.. i want to sum up the values in
my .column (7) in my listbox.. how do i go about doing
this? thanks in advance!
 
with Sum.. now i'm getting "sub or function not defined"
thanks for helping.. any other ideas?
 
I'm sorry, I didn't read the question carefully enough. There are two ways
to do this.

You CAN use the DSum -- IF you save the SQL Statement that fills the
RowSource of the listbox as a saved query. Then you can use it like this:

curCheckReqTotal = DSum("CheckAmt", "DSumTestQuery")

Note: Since you didn't provide table and field names, I created my own. In
this case, CheckAmt is the field that fills Column(7) and DSumTestQuery is
the RowSource for the Listbox saved as a query.

Another option is to loop through the listbox itself (as opposed to going to
the base table) for the information. You can do that with the following
code:

Dim i As Integer
Dim curCheckReqTotal As Single
curCheckReqTotal = 0
For i = 0 To lstboxCheckRequest.ListCount - 1
curCheckReqTotal = curCheckReqTotal + lstboxCheckRequest.Column(7, i)
Next i

Hope that helps.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
Thanks so much!. I used the loop! :)
-----Original Message-----
I'm sorry, I didn't read the question carefully enough. There are two ways
to do this.

You CAN use the DSum -- IF you save the SQL Statement that fills the
RowSource of the listbox as a saved query. Then you can use it like this:

curCheckReqTotal = DSum("CheckAmt", "DSumTestQuery")

Note: Since you didn't provide table and field names, I created my own. In
this case, CheckAmt is the field that fills Column(7) and DSumTestQuery is
the RowSource for the Listbox saved as a query.

Another option is to loop through the listbox itself (as opposed to going to
the base table) for the information. You can do that with the following
code:

Dim i As Integer
Dim curCheckReqTotal As Single
curCheckReqTotal = 0
For i = 0 To lstboxCheckRequest.ListCount - 1
curCheckReqTotal = curCheckReqTotal +
lstboxCheckRequest.Column(7, i)
 
Back
Top