Very difficult to make suggestions until you tell us about your data / table
structure. Where / how are price data stored?
Generic answer:
SELECT TableName.PartID, TableName.PartPrice
FROM TableName
WHERE PartPriceDate =
(SELECT Max(T.PartPriceDate) AS MP
FROM TableName AS T
WHERE T.PartID = TableName.PartID);
If you take a look at the sample Northwind database which comes with Access
you'll see that the Products table has a UnitPrice column in which the
current price of each product is stored. The Order Details table also has a
UnitPrice column in which the price of each product at the time of each order
is stored.
The current price is inserted into a row in the Order Details table when a
new row is added to that table via the Orders Subform by means of the
following code in the AfterUpdate event procedure of the OrderID combo box:
On Error GoTo Err_ProductID_AfterUpdate
Dim strFilter As String
' Evaluate filter before it's passed to DLookup function.
strFilter = "ProductID = " & Me!ProductID
' Look up product's unit price and assign it to UnitPrice control.
Me!UnitPrice = DLookup("UnitPrice", "Products", strFilter)
Consequently when the unit price of a product is changed its simply a matter
of changing, via the Products form, the value of the UnitPrice column in the
relevant row of the Products table. Any new orders will then use this price,
but all previous orders will retain the price in force at the time of the
order.
I'd imagine you might want to do something analogous to this.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.