GrandMasterTuck
In need of medication
- Local time
- Yesterday, 23:32
- Joined
- May 4, 2013
- Messages
- 129
Hi folks. I have a complex database that has lots of tables, but for the purpose of this question, I'll simplify things:
I have a database with a table called Employees. Employees table has EmployeeID, Name, Date of Hire and Gender. I have a second table called WorkDays with EmployeeID, DateOfWork, TimeOfWork. The EmployeeID fields are linked in a one-to-many relationship.
I have a form that has a field called ChosenDate, and some DCount fields below that. The ChosenDate has an AfterUpdate event that writes a TempVar called TheDate, and sets that to the value you enter in the ChosenDate field. The query I mentioned above has the following Criteria in the DateOfWork field:
Total: Max
Criteria: <=[TempVars]![TheDate]
What this all is SUPPOSED to do is just show me the LATEST work date for EVERY employee in the Employees table that is less than or equal to TheDate. But it's not doing that. It's showing me ALL work dates for every employee in Employees that is before TheDate. So for example, if Joe Smith had a work dates of 6/1/15, 6/2/15 and 6/3/15 (3 separate records) in the WorkDates table, and I type 6/4/15 in ChosenDate, I want to see ONE record for Joe Smith in my query for the work date of 6/3/15. Instead, I see THREE records for Joe Smith, one for each of those dates, which throws my calculations off (obviously).
Here's the kicker: I deleted WorkTime from the query, and THEN it works and I get one record for each employee with their work date that was closest to TheDate. But I also want to see the time they worked.
Solution #1 I tried was to add WorkTime back into the query and set that field to Max like WorkDate is set, but then I get the wrong record because it shows me the maximum TIME instead of the maximum date. So for instance, if Joe Smith worked at 0900 on 6/1, 1800 on 6/2 and 1500 on 6/3, and I enter 6/4/2015 into ChosenDate, it shows me 6/2's record instead of 6/3's record.
This is driving me crazy. Does anyone have any insight into why this is messing with me? Does it have anything to do with the order of the columns in the query? (I'm still really patchy at SQL queries, so I use the builder)
Thanks for any input you guys might have. I really appreciate it.
I have a database with a table called Employees. Employees table has EmployeeID, Name, Date of Hire and Gender. I have a second table called WorkDays with EmployeeID, DateOfWork, TimeOfWork. The EmployeeID fields are linked in a one-to-many relationship.
I have a form that has a field called ChosenDate, and some DCount fields below that. The ChosenDate has an AfterUpdate event that writes a TempVar called TheDate, and sets that to the value you enter in the ChosenDate field. The query I mentioned above has the following Criteria in the DateOfWork field:
Total: Max
Criteria: <=[TempVars]![TheDate]
What this all is SUPPOSED to do is just show me the LATEST work date for EVERY employee in the Employees table that is less than or equal to TheDate. But it's not doing that. It's showing me ALL work dates for every employee in Employees that is before TheDate. So for example, if Joe Smith had a work dates of 6/1/15, 6/2/15 and 6/3/15 (3 separate records) in the WorkDates table, and I type 6/4/15 in ChosenDate, I want to see ONE record for Joe Smith in my query for the work date of 6/3/15. Instead, I see THREE records for Joe Smith, one for each of those dates, which throws my calculations off (obviously).
Here's the kicker: I deleted WorkTime from the query, and THEN it works and I get one record for each employee with their work date that was closest to TheDate. But I also want to see the time they worked.
Solution #1 I tried was to add WorkTime back into the query and set that field to Max like WorkDate is set, but then I get the wrong record because it shows me the maximum TIME instead of the maximum date. So for instance, if Joe Smith worked at 0900 on 6/1, 1800 on 6/2 and 1500 on 6/3, and I enter 6/4/2015 into ChosenDate, it shows me 6/2's record instead of 6/3's record.
This is driving me crazy. Does anyone have any insight into why this is messing with me? Does it have anything to do with the order of the columns in the query? (I'm still really patchy at SQL queries, so I use the builder)
Thanks for any input you guys might have. I really appreciate it.