Hello All,
I am a fairly new to Access but have been muddling along. I have an Access project which is due early next week and am having a pain in the *ss problem which I've tried to fix but it's still not working. This database is for our Sheriff's Office. They want to track the types of calls they receive and a whole bunch of other stuff. This is how it's SUPPOSED to work. The user opens the database and logs in. The Main Menu comes up. The user clicks on the My Time In/Time Out button which opens the MyWorkLogF form and enters his time for a particular day (military time). He exits out of that form and from the Main Menu clicks on the Add My Calls button which opens the Calls form. There are two date fields and two time fields on the form. After the user enters the info into these fields, I want the system to check the qryWorkLog to make sure the user is actually on shift for the date and times he entering for the Calls. He can enter many calls for one date. However, the system needs to check that the CallTimeReceived and CallTimeCleared doesn't overlap on any calls.
Worklog Entry: Date In: 02/10/14 Time In: 07:00 Date Out: 02/10/14 Time Out: 17:00
Example: Call Date Received: 02/10/14
Call Time Received: 07:30
Call Date Cleared: 02/10/14
Call Time Cleared: 09:30
For the next call entry if the user tried to enter:
Call Date Received: 02/10/14
Call Time Received: 08:00
Call Date Cleared: 02/10/14
Call Time Cleared: 09:00
The system shouldn't allow the 2nd call entry because the 1st call wasn't cleared yet. They can't be on two different calls at the same time.
When I try to enter a call the system just keeps telling me I'm 'Not on Shift' no matter what times I put in the form. I hope I have explained this well enough so that anyone reading this will no what the heck I'm talking about. I'm not able to upload the database cuz it's too big. If someone out there wants to check it out, I will email it to you. It's only a bit larger than 1.0 mb. The following is the code I'm using:
Code:
Private Sub CallDateReceived_AfterUpdate()
CheckConflict
CheckCallConflict
End SubPrivate Sub CallTimeCleared_AfterUpdate()
CheckTime
CheckConflict
CheckCallConflict
End Sub
Private Sub CallTimeReceived_AfterUpdate()
CheckTime
CheckConflict
CheckCallConflict
End Sub
Sub CheckCallConflict()
If CheckDateTimes = False Then
Exit Sub
End If
Dim ID As Long
ID = 0
Dim ID2 As Long
ID2 = 0
Dim ID3 As Long
ID3 = 0
'Join the Date and Times
Dim CallReceived As Date
Dim CallCleared As Date
'CallReceived = DateValue(CallDateReceived) + DateValue(CallTimeReceived)
CallReceived = Format([CallDateReceived], "Short Date") & " " & Format([CallTimeReceived], "Long Time")
'Format for searching
CallReceived = Format(CallReceived, "dd/mm/yyyy HH:nn:ss")
'CallCleared = DateValue(CallDateCleared) + DateValue(CallTimeCleared)
CallCleared = Format([CallDateCleared], "Short Date") & " " & Format([CallTimeCleared], "Long Time")
'Format for searching
CallCleared = Format(CallCleared, "dd/mm/yyyy HH:nn:ss")
'Check if the EmployeeID matches then the Date/Times for Start and End
ID = Nz(DLookup("CallID", "qryCalls", _
"EmployeeID=" & EmployeeID & " AND " & _
"CallID <> " & CallID & " AND " & _
"CallReceived <= #" & CallReceived & "# AND " & _
"CallCleared > #" & CallReceived & "#"), 0)
ID2 = Nz(DLookup("CallID", "qryCalls", _
"EmployeeID=" & EmployeeID & " AND " & _
"CallID <> " & CallID & " AND " & _
"CallReceived < #" & CallCleared & "# AND " & _
"CallCleared > #" & CallCleared & "#"), 0)
ID3 = Nz(DLookup("CallID", "qryCalls", _
"EmployeeID=" & EmployeeID & " AND " & _
"CallID <> " & CallID & " AND " & _
"CallReceived = #" & CallCleared & "# AND " & _
"CallCleared = #" & CallCleared & "#"), 0)
If ID <> 0 Or ID2 <> 0 Or ID3 <> 0 Then
MsgBox "Call already taken"
DoCmd.RunCommand acCmdUndo
CallTimeReceived.SetFocus
Else
MsgBox "OK Call"
End If
End Sub
Sub CheckTime()
If IsNull(CallTimeReceived) Or CallTimeReceived = "" Then
Exit Sub
ElseIf IsNull(CallTimeCleared) Or CallTimeCleared = "" Then
Exit Sub
Else
If CallTimeReceived > CallTimeCleared Then
MsgBox "'CallTimeReceived' can't be greater than 'CallTimeCleared'"
DoCmd.RunCommand acCmdUndo
CallTimeReceived.SetFocus
End If
End If
End Sub
Sub CheckConflict()
If CheckDateTimes = False Then
Exit Sub
End If
Dim ID As Long
ID = 0
'Join the Date and Times
Dim CallReceived As Date
Dim CallCleared As Date
'CallReceived = DateValue(CallDateReceived) + DateValue(CallTimeReceived)
CallReceived = Format([CallDateReceived], "Short Date") & " " & Format([CallTimeReceived], "Long Time")
'Format for searching
CallReceived = Format(CallReceived, "mm/dd/yyyy HH:nn:ss")
'CallCleared = DateValue(CallDateCleared) + DateValue(CallTimeCleared)
CallCleared = Format([CallDateCleared], "Short Date") & " " & Format([CallTimeCleared], "Long Time")
'Format for searching
CallCleared = Format(CallCleared, "mm/dd/yyyy HH:nn:ss")
'Check if the EmployeeID matches then the Date/Times for Start and End
ID = Nz(DLookup("WorkLogID", "qryWorkLog", _
"EmployeeID=" & EmployeeID & " AND " & _
"DateTimeIn <= #" & CallReceived & "# AND " & _
"DateTimeOut >= #" & CallReceived & "# AND " & _
"DateTimeIn <= #" & CallCleared & "# AND " & _
"DateTimeOut >= #" & CallCleared & "#"), 0)
If ID <> 0 Then
MsgBox "OK Shift"
Else
MsgBox "Not on shift"
DoCmd.RunCommand acCmdUndo
CallTimeReceived.SetFocus
'CallTimeReceived.Text = "" '= Null
'CallTimeCleared = "" '= Null
End If
End Sub
Function CheckDateTimes() As Boolean
CheckDateTimes = True
If IsNull(CallDateReceived) Or CallDateReceived = "" Then
CheckDateTimes = False
ElseIf IsNull(CallTimeReceived) Or CallTimeReceived = "" Then
CheckDateTimes = False
ElseIf IsNull(CallDateCleared) Or CallDateCleared = "" Then
CheckDateTimes = False
ElseIf IsNull(CallTimeCleared) Or CallTimeCleared = "" Then
CheckDateTimes = False
End If
End Function
A ton of thanks to anyone who attempts to help solve this issue from hel*.
BJ