Obviously the price changes daily, and the quantity of shares held changes from time to time.
The 3 basic tables are
Expand|Select|Wrap|Line Numbers
- Investments
- InvestmentID 'Primary Key Autonumber
- SecurityName 'Name of Investment
Expand|Select|Wrap|Line Numbers
- BoughtSold
- BoughtSoldID Primary Key Autonumber
- InvestmentID
- DateBoughtSold
- Balance
Expand|Select|Wrap|Line Numbers
- Valuations
- ValuationID
- InvestmentID
- ValDate
- SharePrice
For simplicity I have set InvestmentID to 172 so that results can be examined
This is Query7 (which I will rename it when it is all working)
Expand|Select|Wrap|Line Numbers
- SELECT Investments.InvestmentID,
- Investments.SecurityName,
- BoughtSold.Balance,
- BoughtSold.DateBoughtSold, Nz(DMax("DateBoughtSold","BoughtSold","BoughtID < "
- & [BoughtID] & " AND InvestmentID = "
- & [Investments]![InvestmentID]),#1/1/1900#)
- AS PrevDate
- FROM Investments INNER JOIN BoughtSold ON Investments.InvestmentID = BoughtSold.InvestmentID
- WHERE (((Investments.InvestmentID)=172))
- ORDER BY BoughtSold.DateBoughtSold;
In the case of the first purchace, I have arbitrarily set the previous date to 01/01/1900.
This works perfectly
This is Query8
Expand|Select|Wrap|Line Numbers
- SELECT Query7.*, Valuations.ValDate,
- Valuations.SharePrice,
- [Balance]*[SharePrice]/100 AS Val
- FROM Valuations
- LEFT JOIN Query7
- ON Valuations.InvestmentID = Query7.InvestmentID
- WHERE (((Valuations.ValDate)<=[DateBoughtSold]
- And (Valuations.ValDate)>[PrevDate]));
I am looking at ways of picking up those final entries. Somehow I feel that Query7 should have an additional line with the Previous Date set to the last date in the table, and an artificial DateBoughtSold set to 31/12/2099 (far in the future)
I would welcome any suggestions.
Phil