我有以下表结构:
tbl_workShift
id PK
employeeid FK
logInTime <- full date
logOutTime <- full date
我正在尝试为员工创建时间表。它使用起来相当简单;员工将从下拉菜单中选择自己,然后单击登录||注销。
登录按钮只是插入一条新记录。
仅当员工想要退出时才会发生这种情况
If(Datediff("h",logInTime,Now())>9)
->create a new record
->insert logOutTime = NOW() ( since the employee forgot to log out yesterday/login today)
else
->update last record with logOutTime = now() ( he didn't forget to login that same day)
我在登出按钮时遇到问题 - 我似乎无法弄清楚如何编写此SQL查询。
答案 0 :(得分:1)
我不知道我是否有足够的信息知道你在做什么来给你提供你正在寻找的帮助......
但是这个vba代码可能会帮助你搞清楚。
Private Sub Employee_AfterUpdate()
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * From tbl_workshift Where employeeid = " & Me!EmployeeId & ";")
If rs.EOF Then
MsgBox "Employee not found."
Exit Sub
Else
If DateDiff("h", Me!LogInTime, Now()) > 9 Then
rs.AddNew
rs!logOutTime = Now()
rs.Update
Else
rs.MoveLast
rs.Edit
rs!logOutTime = Now()
rs.Update
End If
rs.Close
End If
End Sub
祝你好运。