How to book mark a record

bknight
BronzeLounger
Posts: 1389
Joined: 08 Jul 2016, 18:53

How to book mark a record

Post by bknight »

I'm still attempting to put calculations on my current project Anyone that downloaded the code I posted will know where I'm at. If the last record is a Close then a computation should be made. A one to many is bugging me, because the profit will be the last record, if it is a lose, but the closing may be two, three or more from an opening. The opening is the record that I want to book mark, to "jump" back for calculations.
Let attach a sample that should answer many of the questions. There will a wick if statement to do this, and I'll include my code so far.
Work in progress not finished

Code: Select all

Function CalcProfit(Profit)
'This Function Will Calculate The Profit
Dim db As DAO.Database
Dim Rs As DAO.Recordset
Dim Fld2 As Field, Fld3 As Field
Dim Fld4 As Field, Fld6 As Field
Dim Fld11 As Field, Fld12 As Field
Dim I As Long, intCurQty As Integer, intnextQty As Integer, intbackRec As Integer, ContractsLeft As Integer
Dim dblNextAmt As Double, dblCurAmt As Double
Dim strCurSymbol As String, strNextSymbol As String, strCurCon As String, strNextCon As String
Set db = CurrentDb
Set Rs = db.OpenRecordset("Select * From Trades Order By Tradedate")
Set Fld2 = Rs!Tradedate
Set Fld3 = Rs!Symbol
Set Fld4 = Rs!ContractMonth
Set fld5 = Rs!Quantity
Set Fld6 = Rs!ActionID
Set Fld11 = Rs!Amount
Set Fld12 = Rs!Profit
Rs.MoveFirst
Rs.MoveLast
    strCurSymbol = Fld3
    strCurCon = Fld4
    intCurQty = fld5
    dblCurAmt = Fld11
    'Rs.MoveLast
For I = Rs.RecordCount To 2 Step -1
    If I < Rs.RecordCount Then
        If Fld6 = 46 Or Fld6 = 48 Then
        'Find prev opening trades
            If Fld3 = strCurSymbol And Fld4 = strCurCon Then 'And Abs(intCurQty) - Abs(fld5) = 0
            'Found prev opening symbol and contract
                If Abs(fld5) - Abs(intCurQty) <> 0 Then
                    ContractsLeft = fld5 + intCurQty
                'closing quantity equals prev opening quan
                    dblNextAmt = Fld11 / Abs(fld5)
                    Rs.MoveLast ' move to the closing trade
                    'fld5 = ContractsLeft=
                    Rs.Edit
                    Fld12 = dblNextAmt + dblCurAmt
                    Rs.Update
                    If ContractsLeft = 0 Then
                        Exit For
                    End If
                End If
            End If
        End If
    End If
Rs.MovePrevious
Next I
Set Rs = Nothing
Set db = Nothing
End Function
You do not have the required permissions to view the files attached to this post.