
Originally Posted by
fspata
I will want them to scan their ID after hitting the Check Out, which would update their latest Check In record with the Check Out time in the Check Out field which is in the same table
AWW HELL YEAH. I've wanted to do scanning to check-in/out for a while, I'll just live my dream through you. So I'm just gonna fly through what you should do, I suggest doing it in a new database altogether (that you're able to share with us so we can more easily help you should you have more problems).
First, make the check-in/out table:
IDCheckInOut (primary key)
employeeID (foreign key)
timeCheckIn
timeCheckOut
Your Employee table should look something like:
IDEmployee (PK)
ScanningCode (this is the code from the ID they scan)
....
Then make a form for people to scan their ID, controls:
txtIDInput (textbox, and should be your only tabstop)
cmdSubmit (button) - set this button to default (clicked when "enter" is pressed) because as far as I know, scanners emulate "enter" after finishing scanning the barcode. Also set tabstop on this to false.
Now the fun begins. This code is untested, but should give you a good idea of how to do exactly what you want:
Click event for cmdSubmit:
Code:
'this will get the employee's ID from their scanned code. I'm assuming no invalid IDs will be scanned here. You should build that in though
Dim empID as Integer
empID = DLast( "IDEmployee", "tblEmployees", "ScanningCode=" & txtIDInput
'this will look for a timesheet entry where the employee is checked in but not checked out - returns NULL if it can't find it (which means the employee is not checked in)
dim checkInOutID as integer
checkInOutID = DLast( "IDCheckInOut", "tblCheckInOut", "employeeID=" & empID & " AND timeCheckIn IS NOT NULL AND timeCheckOut IS NULL" )
if isnull(checkInOutID) then
'employee is not checked in, add a check in row!
' it's probably a good idea to re-write this to use recordsets and .AddNew rather than what i have below, but this will work.
' this code assumes timeCheckOut allows (and defaults to) null
docmd.setwarnings false
docmd.runsql "INSERT INTO tblCheckInOut ( employeeID, timeCheckIn ) VALUES ( " & empID & ", " & cdbl( now() ) & " ) "
docmd.setwarnings true
else
'employee is checked in, check them out!
' this should be obvious - update the record (where the employee checked in but not out) to check out now.
docmd.setwarnings false
docmd.runsql "UPDATE tblCheckInOut SET timeCheckOut=" & cdbl(now()) & " WHERE IDCheckInOut=" & IDCheckInOut
docmd.setwarnings true
endif
'this may be unnecessary:
txtIDInput.setFocus
Once you've done that, I'd fancy it up a bit with a subform that shows their recent check-in/out times, maybe stay on the screen for like 20 seconds then go away (so the next employee can't see the previous employee's time), etc.
Keep us posted on how this project goes. I'm very excited for you.