473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Returning the first value For a Date Range on a Form (DLookup?)

Hello,

I have created a database to track the flights on three aircraft owned by the flight school I manage. The relevant fields in the FlightRecords table are Date, AircraftID, HourMeterOut, and HourMeterIn. [HourMeterIn] - [HourMeterOut] = TotalFlightTime.
Each month I generate a report that calculates the total flight time for each aircraft. That report calls a Dialog box which has BeginDate and EndDate, BeginHourMeter (which is the first HourMeterOut value for the first day of the month) and EndHourMeter (which is the last HourMeterIn for the last day of the month.
What I would like to do is have the default value of the BeginHourMeter txtBox lookup the first HourMeterOut time for the last month. And the EndHourMeter txtBox lookup the last HourMeterIn time for the last month. I have already figured out how to make the BeginDate and EndDate get the previous month with DateSerial().

Are there any suggestions? I have experimented with DLookup() but to no avail.

Thanks in advance,
Steve
Mar 2 '07 #1
7 2344
Rabbit
12,516 Expert Mod 8TB
If they're sequential you could use DMin and Dmax.
Mar 2 '07 #2
This is what I tried:

=DMin([HourMeterOut],[FOR],[AircraftID]=3 And [Date]=DateSerial(Year(Date()),Month(Date())-1,1))

It came back with "#Name?" error when I loaded the form.

I also tried:

=DMin("[HobbsOut]","[FOR]","[Date]=DateSerial(Year(Date()),Month(Date())-1,1)" And "[AircraftID]=3")

This time is came back with "0"
Mar 2 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
First one should be:

Expand|Select|Wrap|Line Numbers
  1.  
  2. =DMin("[HourMeterOut]","FOR","[AircraftID]=3 AND
  3. Year([Date])=Year(Date()) AND Month([Date])=Month(Date())-1")
  4.  
By using DateSerial you were only returning results where the date was the first of the month.

The second one should be:

Expand|Select|Wrap|Line Numbers
  1.  
  2. =DMin("[HobbsOut]","[FOR]","Year([Date])=Year(Date()) AND Month([Date])=Month(Date())-1 AND [AircraftID]=3")
  3.  
Mary
Mar 2 '07 #4
Thanks Mary,

The first one worked, however I had to change it to:

=DMin("[HobbsOut]","FOR","[AircraftID]=6 AND
Year([Date])=Year(Date()) AND Month([Date])=Month(Date())-1 AND Day(1)")

by adding the AND Day(1) to get the first day of the month.

Now I'm trying to use DMax Function

=DMax("[HobbsIn]","FOR","[AircraftID]=6 AND
Year([Date])=Year(Date()) AND Month([Date])=Month(Date())+1 AND Day(1)-1")

This doesn't return any information. The txtbox is blank. I am trying to get the last HobbsIn time for the end of the previous month.

Thanks,
Steve
Mar 2 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Try this...

Expand|Select|Wrap|Line Numbers
  1. =DMax("[HobbsIn]","FOR","[AircraftID]=6 AND
  2. Year([Date])=Year(Date()) AND Month([Date])=Month(Date())-1 AND Day(DateSerial(Year(Date()), Month(Date()), 1)-1)")
  3.  
Mary
Mar 2 '07 #6
Wonderful!

Thanks so much, those solved all my problems. I am still learning about all the syntax and the way to use functions. They are all there in my head it's just a matter of putting them down right order. Thanks again

Steve
Mar 2 '07 #7
MMcCarthy
14,534 Expert Mod 8TB
Wonderful!

Thanks so much, those solved all my problems. I am still learning about all the syntax and the way to use functions. They are all there in my head it's just a matter of putting them down right order. Thanks again

Steve
You're welcome.
Mar 2 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jason | last post by:
I've got this javascript routine (i found on google - thank you) in an asp.net page that on page reload sets the cursor of a textbox to the last line. It works great! Using a similar concept, I...
3
by: Annette Massie | last post by:
I am trying to insert a record into a table via code and one of the values to add I would like as a dateadd calculation on a value from a query. My code looks like this: Set db = CurrentDb() ...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
6
by: SQL Server | last post by:
I've been working this for a while. Kind of new to SQL Server functions and not seeing what I am doing wrong. I have this function CREATE FUNCTION dbo.test (@Group varchar(50)) RETURNS...
10
by: RoadRunner | last post by:
Hi, I have a employee vacation database that has a vacation table that has the employee name, pay week and date of vacation. I have another lookup table with pay week code and date range for the...
1
by: JonathanParker | last post by:
Another quick one! Trying to search for records by both accounting period and by year in two seperate queries actioned by option buttons. I've sorted the formatting so it's in a UK format but I...
1
by: Beeker | last post by:
I have a table called 'RawData' that collects production data. We run a report on this data everyday to see the performance of each employee. I have another table called 'tblStandards' with...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
5
by: jennwilson | last post by:
Using Access 2000 - I have a query that is suppose to return the records from table within specified time range and find matching data from another table . Table houses Clinician name, location...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.