In the homework from last class (add the button to open the list of all orders), I ended up with a slightly different solution than what was presented in the lesson. In the lesson, a new query was made to bring in the OrderID, customer name and calculate the order total. A form was then made to display the information from the query. In my database, I only created the form and used DLOOKUP and DSUM as the Control Sources for the fields in the form. Both seem to create the same result. Is this merely a case of two different ways of achieving the same end result? Or is there a reason I would want to put the calculations in the query?
Donald Blackwell
@Reply 3 months ago
Hi Tim,
Both methods work, however, each DLookup and DSum in your form makes a separate call to the database for each record in the list as well as for each total.
Using a query that generates calculated fields instead will typically run significantly faster, especially if you have a lot of records or if/when you split your database and your backend tables are on another machine on the network.
Donald is exactly right. Both approaches can produce the same result, but the query is generally the better tool when you are displaying a list of records.
A domain aggregate like DLookup or DSum is essentially Access saying, "For this record, go look through the table and find/calculate this value." If your continuous form displays 100 orders and each row has several domain functions, Access may be performing hundreds of separate lookups and sums.
A query lets Access assemble the recordset in one operation, including joins and totals. That is usually faster, easier to maintain, and much more noticeable once the database is split and the tables live on a network back end.
I use DLookup, DSum, and the other domain aggregate functions mostly for single values: a control on a form header, a validation check, a default value, or a quick calculation where I am only dealing with one record at a time. For a list of orders, I would definitely use the query.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Access Expert 12.