boomer1974
MIS
I have an event log and I need to determine which shift a given event occured on or if it was between shifts. Access does not apply the cirteria I am using and produce the correct result. I have tried every way I can think of Following is my code, any help would be greatly appreciated.
*********************start code*************************
Function Set_Shift()
Dim dbs As Database
Dim rst As Recordset
Dim strsql As String
Dim st As Date
Dim tt As Date
Set dbs = CurrentDb
strsql = "SELECT tbl21303.field1 as st, tbl21303.shift FROM tbl21303 "
Set rst = dbs.OpenRecordset(strsql)
rst.MoveFirst
Do While Not rst.EOF
With rst
tt = TimeValue(rst!st)
If tt > #6:30:00 AM# And tt < #4:30:00 PM# Then
rst.Edit
rst("shift"
= "days"
rst.Update
ElseIf tt > #4:31:00 PM# And tt < #5:00:00 PM# Then
rst.Edit
rst("shift"
= "Between D & N"
rst.Update
ElseIf tt > #6:30:00 PM# And tt < #4:30:00 AM# Then
rst.Edit
rst("shift"
= "Nights"
rst.Update
ElseIf tt > #4:30:00 AM# And tt < #5:00:00 AM# Then
rst.Edit
rst("shift"
= "Between N & D"
rst.Update
Else
rst.Edit
rst("shift"
= "did not work"
rst.Update
End If
rst.MoveNext
End With
Loop
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing
End Function
*********************start code*************************
Function Set_Shift()
Dim dbs As Database
Dim rst As Recordset
Dim strsql As String
Dim st As Date
Dim tt As Date
Set dbs = CurrentDb
strsql = "SELECT tbl21303.field1 as st, tbl21303.shift FROM tbl21303 "
Set rst = dbs.OpenRecordset(strsql)
rst.MoveFirst
Do While Not rst.EOF
With rst
tt = TimeValue(rst!st)
If tt > #6:30:00 AM# And tt < #4:30:00 PM# Then
rst.Edit
rst("shift"
rst.Update
ElseIf tt > #4:31:00 PM# And tt < #5:00:00 PM# Then
rst.Edit
rst("shift"
rst.Update
ElseIf tt > #6:30:00 PM# And tt < #4:30:00 AM# Then
rst.Edit
rst("shift"
rst.Update
ElseIf tt > #4:30:00 AM# And tt < #5:00:00 AM# Then
rst.Edit
rst("shift"
rst.Update
Else
rst.Edit
rst("shift"
rst.Update
End If
rst.MoveNext
End With
Loop
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing
End Function