S
Stephen Lynch
My code works but I cannot figure out how to reset the payment amount when I
get to the next account number. I have the following query that I want to
allocate a balance to. For example, the payment is $300, and I need to
allocate to the largest amount first and then finish it off. For example,
my qry is as such.
AccNumber Symbol Balance Payment
1212 TAVFX 125.00 300.00
1212 JEAVX 100.00 300.00
1212 PEOPX 100.00 300.00
4444 TAVFX 400.00 425.00
4444 JEAVX 100.00 300.00
4444 PEOPX 100.00 300.00
So in the above example, on account 1212, $125 would allocated to TAVFX,
$100 to JEAVX, and then only $75, the balance to PEOPX. Then $400 to TAVFX,
then the balance of $25 to JEAVX.
Here is what I have so far. It works but I cannot figure out how to carry
the new balance for a change in account number.
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strContributionAmount As Currency
Dim strDifference As Currency
Dim strAccNumber As String
Dim strSymbol As String
Dim strAllocationAmount As Currency
Dim strMasterID As String
Dim strBalance As Currency
strSQL = "SELECT tblTradesNewStyle.SchwabNumber,
tblTradesNewStyle.Symbol, tblTradesNewStyle.Difference,
tblTradesNewStyle.ContributionAmount, tblTradesNewStyle.MasterID FROM
tblTradesNewStyle;"
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
strContributionAmount = rs.Fields("ContributionAmount") ' ***** I think
my problem is here! *****
Do While Not rs.EOF
strDifference = rs.Fields("Difference")
strAccNumber = rs.Fields("SchwabNumber")
strSymbol = rs.Fields("Symbol")
strMasterID = rs.Fields("MasterID")
If strContributionAmount <= 0 Then
strAllocationAmount = 0
strBalance = 0
Else
If strContributionAmount >= strDifference Then
strAllocationAmount = strDifference
strBalance = strContributionAmount - strDifference
Else
strAllocationAmount = strContributionAmount
strBalance = 0
End If
End If
If strAllocationAmount > 0 Then
DoCmd.RunSQL "INSERT INTO tblTrades( AccNumber, Symbol, Amount, MasterID)
VALUES('" & strAccNumber & "','" & strSymbol & "', " & strAllocationAmount &
",'" & strMasterID & "')", dbFailOnError
'Carry the balance forward
strContributionAmount = strBalance
rs.MoveNext
Else
strContributionAmount = strBalance
rs.MoveNext
End If
Loop
Exit_Here:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Number & vbCrLf & Err.Description
Resume Exit_Here
Thanks in advance
Steve
get to the next account number. I have the following query that I want to
allocate a balance to. For example, the payment is $300, and I need to
allocate to the largest amount first and then finish it off. For example,
my qry is as such.
AccNumber Symbol Balance Payment
1212 TAVFX 125.00 300.00
1212 JEAVX 100.00 300.00
1212 PEOPX 100.00 300.00
4444 TAVFX 400.00 425.00
4444 JEAVX 100.00 300.00
4444 PEOPX 100.00 300.00
So in the above example, on account 1212, $125 would allocated to TAVFX,
$100 to JEAVX, and then only $75, the balance to PEOPX. Then $400 to TAVFX,
then the balance of $25 to JEAVX.
Here is what I have so far. It works but I cannot figure out how to carry
the new balance for a change in account number.
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strContributionAmount As Currency
Dim strDifference As Currency
Dim strAccNumber As String
Dim strSymbol As String
Dim strAllocationAmount As Currency
Dim strMasterID As String
Dim strBalance As Currency
strSQL = "SELECT tblTradesNewStyle.SchwabNumber,
tblTradesNewStyle.Symbol, tblTradesNewStyle.Difference,
tblTradesNewStyle.ContributionAmount, tblTradesNewStyle.MasterID FROM
tblTradesNewStyle;"
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
strContributionAmount = rs.Fields("ContributionAmount") ' ***** I think
my problem is here! *****
Do While Not rs.EOF
strDifference = rs.Fields("Difference")
strAccNumber = rs.Fields("SchwabNumber")
strSymbol = rs.Fields("Symbol")
strMasterID = rs.Fields("MasterID")
If strContributionAmount <= 0 Then
strAllocationAmount = 0
strBalance = 0
Else
If strContributionAmount >= strDifference Then
strAllocationAmount = strDifference
strBalance = strContributionAmount - strDifference
Else
strAllocationAmount = strContributionAmount
strBalance = 0
End If
End If
If strAllocationAmount > 0 Then
DoCmd.RunSQL "INSERT INTO tblTrades( AccNumber, Symbol, Amount, MasterID)
VALUES('" & strAccNumber & "','" & strSymbol & "', " & strAllocationAmount &
",'" & strMasterID & "')", dbFailOnError
'Carry the balance forward
strContributionAmount = strBalance
rs.MoveNext
Else
strContributionAmount = strBalance
rs.MoveNext
End If
Loop
Exit_Here:
On Error Resume Next
rs.Close
Set rs = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Number & vbCrLf & Err.Description
Resume Exit_Here
Thanks in advance
Steve