Adding values in a listbox

D

Don

I have a textbox called txtTOT_MINUTES and a listbox called lstHOURS. I want
to return the sum of column 7 in my listbox. I wrote the following code in
VBA but it does not work. Any help would be appreciated.


Me.txtTOT_MINUTES = Sum(Me.lstHOURS.Column(7))
 
K

KARL DEWEY

You are trying to use the listbox wrong. A listbox is the source for a pick
list, not to store data as you would in a table.

Explain a little about what you are trying to accomplish and someone might
be able to suggest a method to do it.
 
D

Don

My listbox lists an employee's hours worked each day. In column 7 is the
value that represents the total minutes worked for that day. I would like to
populate the textbox with the total number of minutes worked for the week.

I realize the listbox is to be used as a way to select a value . . . and
mine is also; however, I'd like to have the ability to show the total minutes
worked. I will use this number to determine how much time is overtime. Your
help would be appreciated.
 
K

KARL DEWEY

Use a record per employee per day worked. Then use a totals query to sum for
the week.
 
S

Stu

WORK AROUND:

Private Sub ListTotal()
Dim lTotal As Long
Dim rs As Recordset
Dim con As Connection
Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset") ' Recordset

sSQL = Me.RequestList.RowSource
rs.Open sSQL, con
lTotal = 0

While rs.EOF = False
' MsgBox (rs(0) & " " & rs(4)) ' Display first column, fourth column. If
needed
lTotal = lTotal + rs(4) ' Total the fourth column
rs.MoveNext
Wend

Me.ColumnTotal = lTotal ' Put Total in Unbounded text box
rs.Close
Set rs = Nothing
Set con = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top