L
Les Coover
There is a table named tblBasis that has
the number of shares purchased for each investment
over a period of time. Some investments
may contains several entries in the
Number_Shares field since more than
one purchase of the same stock occurs.
I want to extract the total sum of shares
for each investment.
It tried the following but it is not correct.
I can easily do this with a query, but my
objective is to create a from that has
totals for each investment with a subform
that lists the specific investments over
a time period. When I tried to make
a form and subform based on the query
it did not work. Any advice welcomed.
Dim Number_Shares As Double
'Calculate market value for each investment
Function CMV(Market_Symbol As String, Current_Mkt_Price As Currency) As
Currency
Dim db As Database, rec As Recordset, myAcum As Currency
Set db = CurrentDb()
Set rec = db.OpenRecordset("tblBasis", dbOpenDynaset)
rec.MoveFirst
myAcum = 0
Do Until rec.EOF
If Market_Symbol = Market_Symbol Then
myAcum = Number_Shares + myAcum
End If
rec.MoveNext
Loop
CMV = myAcum
End Function
the number of shares purchased for each investment
over a period of time. Some investments
may contains several entries in the
Number_Shares field since more than
one purchase of the same stock occurs.
I want to extract the total sum of shares
for each investment.
It tried the following but it is not correct.
I can easily do this with a query, but my
objective is to create a from that has
totals for each investment with a subform
that lists the specific investments over
a time period. When I tried to make
a form and subform based on the query
it did not work. Any advice welcomed.
Dim Number_Shares As Double
'Calculate market value for each investment
Function CMV(Market_Symbol As String, Current_Mkt_Price As Currency) As
Currency
Dim db As Database, rec As Recordset, myAcum As Currency
Set db = CurrentDb()
Set rec = db.OpenRecordset("tblBasis", dbOpenDynaset)
rec.MoveFirst
myAcum = 0
Do Until rec.EOF
If Market_Symbol = Market_Symbol Then
myAcum = Number_Shares + myAcum
End If
rec.MoveNext
Loop
CMV = myAcum
End Function