I agree 110% with Marshall that the shifts should be stored as rows in a table. The shift names and times are data , and data should only be stored as values in rows in tables, not hard-coded in code or an SQL statement. This was in fact Codd's Rule
#1, the Information Rule, when he first put forward the database relational model in 1970 and was later expressed by Date as the Information Principle:
'The entire information content of the database is represented in one and only one way, namely as explicit values in column positions in rows in tables'.
C J Date - Introduction to Database Systems; 7th Edition; 2000
You can then return the shift for any time in a query like so:
SELECT [CompletionDate], [Shift]
FROM [Timesheet] INNER JOIN [Shifts]
ON TimeValue(([Timesheet].[CompletionDate]) BETWEEN
[Shifts].[StartTime] AND [Shifts].[EndTime]);
Note that the join condition must be enclosed in parentheses when using a BETWEEN....AND operation in the JOIN clause.
A practical implication of this is of course that, in the event of the shift times changing, it's merely a case of updating the rows in the Shifts table. However, this will affect existing timesheet records as well as new ones, so if the historical shift pattern
needs to be preserved in the timesheet records the Shift value obtained from the Shifts table will need to be assigned to a Shift column in the timesheet table rather than merely 'pulled' in from it in a query. This would be done in the timesheet data input
form in the AfterUpdate event procedure of the CompletionDate control with code like so:
Dim strCriteria As String
strCriteria = "#" & Format(Me.[CompletionDate],"hh:nn:ss") & _
"# Between [StartTime] And [EndTime]"
Me.[Shift] = DLookup("Shift", "Shifts", strCriteria)
Ken Sheridan, Stafford, England