WineSnob
Not Bright but TENACIOUS
- Local time
- Today, 13:00
- Joined
- Aug 9, 2010
- Messages
- 211
I have a table called [tblIncomeTemp] with fields [Yr](1,2,3,.....) and [Desired Income] and [ProposalID].
I am TRYING to loop through the table and add up the [Desired Income] for a specified number of Years. Not sure how to do that though. Below is what I am trying to use. Something is wrong though!
Thanks in advance for any help.
Function GetDesiredIncomeTotal(nProposalID As Long, nYears As Integer) As Currency
Dim cDesiredIncomeTotal As Currency
Dim rs As Recordset
Dim nYear As Integer
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [tblIncomeTemp] WHERE [ProposalID] = " & nProposalID)
While Not rs.EOF
For nYear = 1 To nYears
Debug.Print nYear
If nYear = 1 Then
cDesiredIncomeTotal = rs![Desired Income]
Else
cDesiredIncomeTotal = rs![Desired Income] + rs![Desired Income]
End If
Next nYear
rs.MoveNext
Wend
GetDesiredIncomeTotal = cDesiredIncomeTotal
Debug.Print GetDesiredIncomeTotal
End Function
Function TestGetDesiredIncCalc()
GetDesiredIncomeTotal 1003, 5
End Function
I am TRYING to loop through the table and add up the [Desired Income] for a specified number of Years. Not sure how to do that though. Below is what I am trying to use. Something is wrong though!
Thanks in advance for any help.
Function GetDesiredIncomeTotal(nProposalID As Long, nYears As Integer) As Currency
Dim cDesiredIncomeTotal As Currency
Dim rs As Recordset
Dim nYear As Integer
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [tblIncomeTemp] WHERE [ProposalID] = " & nProposalID)
While Not rs.EOF
For nYear = 1 To nYears
Debug.Print nYear
If nYear = 1 Then
cDesiredIncomeTotal = rs![Desired Income]
Else
cDesiredIncomeTotal = rs![Desired Income] + rs![Desired Income]
End If
Next nYear
rs.MoveNext
Wend
GetDesiredIncomeTotal = cDesiredIncomeTotal
Debug.Print GetDesiredIncomeTotal
End Function
Function TestGetDesiredIncCalc()
GetDesiredIncomeTotal 1003, 5
End Function