Access 2003 Report

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I just learned from a help article how to use DLookUp to get a value from a
field in a previous record. That value will be used in 2 or 3 computations.
I found that I could get that function to work in a table designed for my
car's gasoline consumption.

Question: Will it be necessary to get that data once for each of those
calculations, or is there a way to retrieve that value just once and perform
those calculations based on the retrieved value?

Thanks in advance.
 
Are you using the DLookup in a calculated field in the report's Record
Source query? Or in an expression for a textbox's Control Source on the
report?

More details about what your setup is will help us make some suggestions.
 
A. Database (’96 Voyager) table fields: ID, Date, Odometer, Gallons, Cost,
$PG, Comment.
B. Each record = each tank fill up.
C. The first record is only needed for the starting Odometer reading and
date. Odometer is used to calculate miles driven.
D. Without a Query, the report output always included a record for the first
entry (not good).
E. Created a Query to ignore the first record (ID > 1).
F. Created a Report attached to the Query.
G. Used the DLookUp function in a text box to retrieve the previous Odometer
reading (It worked!!)
1. There was no data output from record ID = 1.
2. There was normal output from each of the remaining records. Each of
these included the Odometer reading from the previous record.
H. Next: I need to calculate miles driven, miles per gallon, and dollars
per gallon for each record.
 
Using DLookup in the textbox is good. Now you can use the textbox's value in
other textboxes' control sources directly, without having to redo the
DLookup function in each of those other textboxes.

Assuming that a textbox named "txtLookUp" is the one with the DLookup
function, you can write a control source for "miles driven" textbox this
way:

=[FieldNameWithOdometerValue] - [txtLookUp]

etc.
 
Just a follow-up note: Thanks, Ken, for your suggestion. I many have
finally figured it out, but I don't think I have that many years left.
--
Wayne M


Ken Snell (MVP) said:
Using DLookup in the textbox is good. Now you can use the textbox's value in
other textboxes' control sources directly, without having to redo the
DLookup function in each of those other textboxes.

Assuming that a textbox named "txtLookUp" is the one with the DLookup
function, you can write a control source for "miles driven" textbox this
way:

=[FieldNameWithOdometerValue] - [txtLookUp]

etc.
--

Ken Snell
<MS ACCESS MVP>
 
Back
Top