Share via

MS Access filter query based on time

Anonymous
2016-11-23T12:13:23+00:00

Would appreciate a help to on this. First of all I am not sure if this is a possibility with MS Access.

I would like my query to filter records based on time. For e.g: Below query showing employees checked-in to worksite and active at worksite (not checked-out). Note: check-in and check-out time are pre-entered into the table with each employee.

EmpID Name Check-inTime Check-outTime
45 Peter 1400 1530

As per above query, I want filter those staff who has checked-in (when system time is 1400hrs)  and when they checked-out (when system time is 1530hrs) it should not appear in query. Can it be automatically filtered based on system time? Like, when system time is 1400hrs, the record should showup and when system time reaches to 1530hrs records should automatically disappear from query. And I can use this query as record source for my form.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2016-11-25T16:08:43+00:00

Is this what you are attempting?

SELECT FirstName, LastName

FROM Employees INNER JOIN TimeLog

ON Employees.EmployeeID = TimeLog.EmployeeID

WHERE NOW() BETWEEN DATEADD("n",-15,WorkDate+TimeStart)

AND WorkDate+TimeEnd + IIF(TimeStart > TimeEnd,1,0);

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2016-11-23T23:07:52+00:00

Change it to:

SELECT FirstName, LastName

FROM Employees INNER JOIN TimeLog

ON Employees.EmployeeID = TimeLog.EmployeeID

WHERE NOW() BETWEEN WorkDate+TimeStart

AND WorkDate+TimeEnd + IIF(TimeStart > TimeEnd,1,0);

Was this answer helpful?

0 comments No comments

8 additional answers

Sort by: Most helpful
  1. Anonymous
    2016-11-23T19:42:25+00:00

    What is the datatype of your time fields?

    Its Date/time format

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-11-23T18:01:37+00:00

    What is the datatype of your time fields?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-11-23T14:40:14+00:00

    Hi,

    perhaps you can use this expressions as criteria:

    Check-inTime

    <=left(time,2) & mid(time,4,2)

    Check_outTime

    >=left(time,2) & mid(time,4,2)

    Ciao Mimmo

    Was this answer helpful?

    0 comments No comments