Query to Return Earliest Contract Date

music_al

Registered User.
Local time
Today, 17:43
Joined
Nov 23, 2007
Messages
200
Hi

I have a table of staff with (for simplicity)...
  • Spot_ID (this is the Staff ID)
  • Full_Name
  • Initial_Start_Date
  • and other stuff...
The 'Initial Start Date' is the start date of the staff member's very first contract using this Dlookup...

=DLookUp("[MinOfStart_Date]","[qry_Initial_Start_Date2]")


I have a related table that stores their contracts, with...
  • Spot_ID
  • Start Date
  • Role
  • End Date
  • and other stuff
In the staff table I am trying to show the start date of the very first contract that is in the Contracts table for each member of staff.

The problem is, the earliest date of one of the staff records is being shown against the other record. What am I doing wrong ?

Initial_Start_Date_Query.PNG
Dlookup_Query_Results.PNG
 
Create an aggregate query for the Contracts table using the totals button and add SpotID and InitialStartDate fields.
In the Totals row of the query design change InitialStartDate to Min.
Run your query.
 
Colin, isn't that what I've done ? See the screen shots.
 
Maybe I need to understand what an AGGREGATE query is.
 
Even though INITIAL START DATE isn't actually in the Contracts table ?
 
Surely you need criteria as well?


Code:
=DLookUp("[MinOfStart_Date]","[qry_Initial_Start_Date2]", "Spot_ID = " & Me.SpotID )

Hi

I have a table of staff with (for simplicity)...
  • Spot_ID (this is the Staff ID)
  • Full_Name
  • Initial_Start_Date
  • and other stuff...
The 'Initial Start Date' is the start date of the staff member's very first contract using this Dlookup...

=DLookUp("[MinOfStart_Date]","[qry_Initial_Start_Date2]")


I have a related table that stores their contracts, with...
  • Spot_ID
  • Start Date
  • Role
  • End Date
  • and other stuff
In the staff table I am trying to show the start date of the very first contract that is in the Contracts table for each member of staff.

The problem is, the earliest date of one of the staff records is being shown against the other record. What am I doing wrong ?

View attachment 72293
View attachment 72294
 
Sorry - use Start_Date field from Contracts table - see screenshot for an aggregate (totals) query
 

Attachments

  • Capture.PNG
    Capture.PNG
    60.9 KB · Views: 105
Ive copied the last argument in but its now saying its Invalid Syntax.
 
Gasman, should you last argument include the UNDERSCORE between Spot and ID ?
Spot_ID

Because I've added this and I now get a #NAME? in the field.
 
I had created an aggregate query first. That is shown in my screenshot.

Initial_Start_Date_Query1.PNG

This is then used in my second query which I show in my first post.
 
Ah but I'm not psychic!
So what was wrong with the original aggregate query ... and why do you need both dates from table & query?
 
OK, I've got it to work by adding the criteria argument that Gasman added (but had to fix the error he'd made.

the Dlookup should have been...

=DLookUp("[MinOfStart_Date]","[qry_Initial_Start_Date2]","Spot_ID=" & [Spot_ID])

However...

In the New Record row, I'm now seeing #Error. How do I suppress this ??
 
Pardon me for a typing error.

OK, I've got it to work by adding the criteria argument that Gasman added (but had to fix the error he'd made.

the Dlookup should have been...

=DLookUp("[MinOfStart_Date]","[qry_Initial_Start_Date2]","Spot_ID=" & [Spot_ID])

However...

In the New Record row, I'm now seeing #Error. How do I suppress this ??
 
Sorry, wasn't meant as a criticism just wanted to help any future readers of this post.
 

Users who are viewing this thread

Back
Top Bottom