I’m having trouble creating a query.
I need to create a SQL query where ProductID = prodSelect (user choice) and EndTime = Null and StartTime < 3 hours from the current time.
This is what I have so far. Could someone help me figure it out?
Set rs = CurrentDb.OpenRecordset("SELECT TimeID " & _
"FROM tblLunchTime " & _
"WHERE ProductionID = prodSelect
AND EndTime = NULL
AND StartTime < (Now - 0/0/0000 3: 00: 00 AM")
The condition
AND EndTime = NULLalways evaluates to unknown. Instead, use:Then, you probably should tell the database how to parse the datetime string. This would work on MS Access (to require StartTime to be more than 3 hours in the past):
Per your comment, here is a full query:
The problem might be your prodId; I’m not sure what it’s supposed to mean. You might try to use it as a variable, like