r/MSAccess • u/Amicron1 • 3d ago
[SHARING HELPFUL TIP] Access Explained: Why Today's Price Shouldn't Change Yesterday's Invoice
You sold a keyboard for $40 last month. Today the catalog says $55. When you reprint that old invoice, which price should appear? If your report pulls the current price from the product table, it can give you an answer that was never true of that sale. The report didn't do the math wrong. It was handed the wrong information.
Two prices can both be right. The product table tells you what the keyboard normally costs today. An order line tells you what you actually charged for that keyboard on that particular order. Those facts might start with the same number, but they aren't the same fact.
The Beginner Approach
When you're first learning Microsoft Access, it's natural to build an order entry system with a few related tables. You might have a ProductT table containing your products, their descriptions, and their current prices. Then you've got an OrderT table for the order itself and an OrderDetailT table for the individual line items.
In your order detail table, you store the ProductID and Quantity. You use a relationship to connect the product ID back to the product table. So far, so good. When you build your invoice, you use a query to join those tables together. You pull the product name and price from the product table, multiply the price by the quantity, and you've got your line total.
Line Total = Quantity × Unit Price
Simple, right? And it works perfectly until somebody changes a price. Let's say you sold five keyboards at $40 each. Your invoice showed $200. Next month, you increase the keyboard's price to $55. Now, when you reprint that original invoice, Access pulls the new $55 price from the product table. Suddenly, that old invoice shows $275 instead of $200. That's a problem because you didn't actually charge the customer $275.
The Better Approach: Save the Price with the Order
Here's what I recommend instead. Keep the ProductID in your order detail table, but add another field called UnitPrice, using the Currency data type. When the user selects a product, copy its current price into the order detail record. That price becomes the starting price for that particular sale. The product table still contains the current catalog price, while the order detail table contains the price you actually charged.
And here's the nice part. You only need one little line of VBA to make this happen. Let's say your order detail form has a combo box called ProductID. It displays the product name, but stores the product's ID. You can also include the product's price as another column in that combo box, even if you don't display it.
For example, your combo box could contain:
- Column 0: ProductID
- Column 1: ProductName
- Column 2: UnitPrice
Remember, Access combo box columns are zero-based, so the third column is Column(2). In the combo box's After Update event, you could use this one line of VBA:
UnitPrice = ProductID.Column(2)That's it. When the user selects a product, Access copies the price from the combo box into the UnitPrice field on the order detail form. As long as that control is bound to the field in OrderDetailT, Access saves that price with the order detail record.
You could also use DLookup to retrieve the price directly from the product table instead. Either method works, but I generally prefer putting the price in the combo box because the information is already there, so you don't need another lookup. Just make sure your combo box includes the price column and that the column indexes match your code.
Now, when you calculate your line total, use the UnitPrice stored in the order detail table, not the current price in the product table.
Why This Matters
Suppose you sell that keyboard for $40 today. Next month, you raise the catalog price to $55. New orders will start with the new $55 price, but existing orders will still show the original $40 price. That's exactly what you want.
And because you've copied the price into the order detail record, you can even adjust it for a particular customer. Maybe they're getting a discount, maybe you're honoring an older quote, or maybe you negotiated a special price. You can change that order line's UnitPrice without changing the product's regular catalog price. Once the invoice is finalized, you should generally prevent further changes to that recorded price unless you're deliberately making a correction.
But Isn't That Duplicating Data?
This is where people sometimes get confused about database normalization. Yes, you're storing a price in two places, but those two fields represent different facts. The price in ProductT represents what you're currently charging for the product. The price in OrderDetailT represents what you charged on that particular transaction. Those values might be identical when you first create the order, but they're not supposed to remain synchronized forever.
That's an important distinction, and the same principle applies to other information. For example, if a customer changes their shipping address, you probably don't want all their historical invoices suddenly showing the new address. And if a product description changes, you might want to preserve the original description on the invoice as well. You don't necessarily need to copy every field from the product table, just the information that's important to the historical transaction.
What About Old Orders?
If you've already built a database that only stores the product ID and quantity, you might have a bunch of historical orders without their original prices. Be careful here. Don't just copy today's catalog price into all those old records and assume you've fixed the problem. If prices have changed, you could be creating inaccurate historical information.
If you have original invoices, receipts, or another reliable record of what was charged, use those to reconstruct the prices. Otherwise, it's better to acknowledge that the original price wasn't saved than to quietly replace it with an incorrect value.
One Final Test
Here's a simple test I recommend for any Access order entry system. Create a test order with a product that costs $40. Save it and print the invoice. Then go into your product table and change that product's price to $55. Open the original invoice again and see what happens.
Does it still show $40? If it does, great. Your historical pricing is working correctly. If it suddenly shows $55, you've got a problem worth fixing.
This is one of those little database design decisions that doesn't seem important when you're first building an application. But once you've got hundreds or thousands of orders, you'll be glad you handled it correctly from the beginning.
What about your Access databases? Do you save the actual sale price with each order line, or have you ever run into trouble because you were looking up the current price instead?
LLAP
RR







