raziel3
Registered User.
- Local time
- Today, 13:32
- Joined
- Oct 5, 2017
- Messages
- 316
Hello all,
If you happened to come across my posts, most of my questions are related to getting the latest price or rate during data entry. I've gotten lots of help on the forums dealing with it but I think I may have a better solution.
A typical pricing/rate table looks like this:
Some like to include ENDDATEs but I like using a query to deal with that and not put the ENDDATES at table level, thanks to @arnelgp for showing me how to to do that:
Records Table:
There are many ways to get the current price, they may include a Dlookup, Select Top 1, Making a Latest Price Query and JOIN it, Subquery etc. They are all good but when your records table starts to increase they all have efficiency problems, especially if you are generating a Report or using a Continuous Form for Data Entry.
My solution (and I may get some heat for this) is to add a column/field to the Records table to fill in the Current PriceID at the time of Data Entry. I have found that only after associating each Record to the PRICEID many of my downstream queries and reports were so easier to generate.
You only need to run one of the Functions once after an Event in your Data Entry Form that populates the PRICEID field in your table. This saves you having to create 3 to 5 queries to get the results you want. (Additionally, you can also run and UPDATE Query to populate the PRICEID Field)
Records Table New:
I know many of the seasoned db Developers will say that populating a field in a table that can otherwise be gotten from a running a query is poor practice but as I said before, after a while the queries tend to become slow and volatile causing Access to freeze and crash (that's just my experience, it may not be your case).
Anyways, would appreciate any feedback and criticisms.
If you happened to come across my posts, most of my questions are related to getting the latest price or rate during data entry. I've gotten lots of help on the forums dealing with it but I think I may have a better solution.
A typical pricing/rate table looks like this:
Code:
+---------+-----------+----------+--------+
| PRICEID | ITEMID | EFFDATE | PRICE |
+---------+-----------+----------+--------+
| 001 | PRODUCT_A | 1/1/2022 | $5.00 |
| 002 | PRODUCT_B | 2/1/2022 | $10.00 |
| 003 | PRODUCT_A | 5/1/2022 | $6.00 |
+---------+-----------+----------+--------+
Some like to include ENDDATEs but I like using a query to deal with that and not put the ENDDATES at table level, thanks to @arnelgp for showing me how to to do that:
Code:
+---------+-----------+-----------+------------+-------+
| PRICEID | ITEMID | STARTDATE | ENDDATE | PRICE |
+---------+-----------+-----------+------------+-------+
| 001 | PRODUCT_A | 1/1/2022 | 4/30/2022 | $5.00 |
| 002 | PRODUCT_B | 2/1/2022 | 12/31/9999 | $5.00 |
| 001 | PRODUCT_A | 5/1/2022 | 12/31/9999 | $5.00 |
+---------+-----------+-----------+------------+-------+
Records Table:
Code:
+--------+-----------+-----------+-----+
| SALEID | ITEMID | SALEDATE | QTY |
+--------+-----------+-----------+-----+
| 001 | PRODUCT_A | 1/15/2022 | 3 |
| 002 | PRODUCT_B | 1/16/2022 | 9 |
| 003 | PRODUCT_B | 1/17/2022 | 4 |
| 004 | PRODUCT_A | 5/2/2022 | 2 |
+--------+-----------+-----------+-----+
There are many ways to get the current price, they may include a Dlookup, Select Top 1, Making a Latest Price Query and JOIN it, Subquery etc. They are all good but when your records table starts to increase they all have efficiency problems, especially if you are generating a Report or using a Continuous Form for Data Entry.
My solution (and I may get some heat for this) is to add a column/field to the Records table to fill in the Current PriceID at the time of Data Entry. I have found that only after associating each Record to the PRICEID many of my downstream queries and reports were so easier to generate.
You only need to run one of the Functions once after an Event in your Data Entry Form that populates the PRICEID field in your table. This saves you having to create 3 to 5 queries to get the results you want. (Additionally, you can also run and UPDATE Query to populate the PRICEID Field)
Records Table New:
Code:
+---------+-----------+-----------+-----+---------+
| SALESID | ITEMID | SALEATE | QTY | PRICEID |
+---------+-----------+-----------+-----+---------+
| 001 | PRODUCT_A | 1/15/2022 | 3 | 001 |
| 002 | PRODUCT_B | 1/16/2022 | 9 | 002 |
| 003 | PRODUCT_A | 1/17/2022 | 4 | 001 |
| 004 | PRODUCT_A | 5/2/2022 | 2 | 003 |
+---------+-----------+-----------+-----+---------+
I know many of the seasoned db Developers will say that populating a field in a table that can otherwise be gotten from a running a query is poor practice but as I said before, after a while the queries tend to become slow and volatile causing Access to freeze and crash (that's just my experience, it may not be your case).
Anyways, would appreciate any feedback and criticisms.
Last edited: