directormac
Occasional Presence
- Local time
- Today, 10:56
- Joined
- Oct 24, 2001
- Messages
- 259
Hey Gang. Well, thanks to the Access World Forum's many helpful members, I'm venturing into coding some VBA, rather than using multiple hidden forms, queries, etc. to create convulted code-free solutions. Here's the latest item to be re-examined, but I haven't spotted the VBA solution yet...
Take a simple table that includes just dates and amounts:
TABLE: tblReadings
FIELD: timeReadingDate PRIMARY KEY
TYPE: Date/Time
REQUIRED: Yes
INDEXED: Yes, no dupes
FIELD: longReadingAmount
TYPE: Long Integer
REQUIRED: Yes
INDEXED: No
Now, it seems silly to me to record the difference/volume with every record, since that's a calculated value (today's reading, less yesterday's reading, equals yesterday's volume). However, my current implementation seems inelegant.
First, I have a query that repeats the two original fields, sorting the reading table in ascending order by the dateReadingDate field:
QUERY: qryReadingsByDates
FIELD: timeReadingDate
TABLE: tblReadings
SORT: Ascending
FIELD: longReadingAmount
TABLE: tblReadings
SORT: None
Then I have a second, separate query that takes the first one, repeats the fields again, and adds the longVolume field:
QUERY: qryReadingsWithVolumes
FIELD: timeReadingDate
TABLE: tblReadingsByDates
SORT: None
FIELD: longReadingAmount
TABLE: tblReadingsByDates
SORT: None
FIELD: longVolume:
The longVolume field contains the following expression
longVolume: IIf([timeDate]=DMin("[timeDate]","qryReadingsByDate"),[longAmount],[longAmount]-(DSum("[longAmount]","qryReadingsByDate","[timeDate] =#" & (DMax("[timeDate]","qryReadingsByDate","[timeDate] < #" & [timeDate] & "#")) & "#")))
Then, if I want to to take a further step (say, for example, examining readings and volumes that occur between selected dates), it means adding a THIRD query, making the chain even LONGER...
It occurs to me to wonder if there's not a shorter and faster way to do this in a VBA function. Surely there's something better than slogging through a series of 2 (MINIMUM!) nested queries every time I want to include the volume on a form or report?
All ideas welcome...
--Newbie-Once-Again Mac
Take a simple table that includes just dates and amounts:
TABLE: tblReadings
FIELD: timeReadingDate PRIMARY KEY
TYPE: Date/Time
REQUIRED: Yes
INDEXED: Yes, no dupes
FIELD: longReadingAmount
TYPE: Long Integer
REQUIRED: Yes
INDEXED: No
Now, it seems silly to me to record the difference/volume with every record, since that's a calculated value (today's reading, less yesterday's reading, equals yesterday's volume). However, my current implementation seems inelegant.
First, I have a query that repeats the two original fields, sorting the reading table in ascending order by the dateReadingDate field:
QUERY: qryReadingsByDates
FIELD: timeReadingDate
TABLE: tblReadings
SORT: Ascending
FIELD: longReadingAmount
TABLE: tblReadings
SORT: None
Then I have a second, separate query that takes the first one, repeats the fields again, and adds the longVolume field:
QUERY: qryReadingsWithVolumes
FIELD: timeReadingDate
TABLE: tblReadingsByDates
SORT: None
FIELD: longReadingAmount
TABLE: tblReadingsByDates
SORT: None
FIELD: longVolume:
The longVolume field contains the following expression
longVolume: IIf([timeDate]=DMin("[timeDate]","qryReadingsByDate"),[longAmount],[longAmount]-(DSum("[longAmount]","qryReadingsByDate","[timeDate] =#" & (DMax("[timeDate]","qryReadingsByDate","[timeDate] < #" & [timeDate] & "#")) & "#")))
Then, if I want to to take a further step (say, for example, examining readings and volumes that occur between selected dates), it means adding a THIRD query, making the chain even LONGER...
It occurs to me to wonder if there's not a shorter and faster way to do this in a VBA function. Surely there's something better than slogging through a series of 2 (MINIMUM!) nested queries every time I want to include the volume on a form or report?
All ideas welcome...
--Newbie-Once-Again Mac