Originally posted by atc
Why has your user profile changed? Which should I send a PM to?
Mary
"AND [ScheduleDate]=#" & Me.[BookingsSubform].Form![ScheduleDate] & "#")
"AND [ScheduleDate]=#" & Me.[BookingsSubform].Form![ScheduleDate] & "#")
Set rs = db.OpenRecordset("SELECT [ScheduleStartTime], [ScheduleEndTime] " & _
"FROM Schedule INNER JOIN ScheduleDetails " & _
"ON Schedule.ScheduleID=ScheduleDetails.ScheduleID " & _
"WHERE [CourtID]=" & Me.[BookingsSubform].Form![CourtID] & " " & _
"AND [ScheduleDate]=#" & Me.[BookingsSubform].Form![ScheduleDate] & "#")
Private Sub ScheduleEndTime_AfterUpdate()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMessage As String
Dim startTime As Date
Dim endTime As Date
Dim test As Boolean
test = False
If Me.NewRecord = True Then
Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT [ScheduleStartTime], [ScheduleEndTime] " & _
"FROM Schedule INNER JOIN ScheduleDetails " & _
"ON Schedule.ScheduleID=ScheduleDetails.ScheduleID " & _
"WHERE [CourtID]=" & Forms![Bookings]![BookingsSubform].Form![CourtID] & " " & _
"AND [ScheduleDate]=#" & Forms![Bookings]![BookingsSubform].Form![ScheduleDate] & "#")
startTime = Me.ScheduleStartTime
endTime = Me.ScheduleEndTime
If rs.RecordCount = 0 Then Exit Sub
rs.MoveFirst
Do Until rs.EOF
If startTime = rs!ScheduleStartTime Or endTime = rs!ScheduleEndTime Then
test = True
ElseIf startTime > rs!ScheduleStartTime And startTime < rs!ScheduleEndTime Then
test = True
ElseIf endTime < rs!ScheduleEndTime And endTime > rs!ScheduleStartTime Then
test = True
End If
If test Then
rs.MoveLast
End If
rs.MoveNext
Loop
If test = False Then
MsgBox ("Time is available")
Else
MsgBox ("Time is unavailable")
Me.ScheduleStartTime = Null
Me.ScheduleEndTime = Null
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End If
End Sub
Private Sub Form_AfterUpdate(Cancel As Integer)
Dim strWhere As String
Dim varKey As Variant
strWhere = "(CourtID=" & Me.CourtID & ") AND " & _
"(ScheduleDate=" & Format(Me.ScheduleDate, "\#m/d/yyyy\#") & ")"
varKey = DLookup("[CourtID] & Format([ScheduleDate],' \- d mmm yyyy')", _
"[Courts]", _
strWhere)
If Not IsNull(varKey) Then
Cancel = True
Call MsgBox(strWhere & vbCrLf & varKey)
Debug.Print strWhere & vbCrLf & varKey
End If
End Sub
Private Sub ScheduleDate_AfterUpdate()
If Not IsNull(Me.CourtID) Then
CheckDate
End If
End Sub
Private Sub CourtID_AfterUpdate()
If Not IsNull(Me.ScheduleDate) Then
CheckDate
End If
End Sub
Function CheckDate()
Dim strWhere As String
Dim varKey As Variant
strWhere = "(CourtID=" & Me.CourtID & ") AND " & _
"(ScheduleDate=" & Format(Me.ScheduleDate, "\#m/d/yyyy\#") & ")"
varKey = DLookup("[CourtID] & Format([ScheduleDate],' \- d mmm yyyy')", _
"[Courts]", _
strWhere)
If Not IsNull(varKey) Then
Call MsgBox(strWhere & vbCrLf & varKey)
Debug.Print strWhere & vbCrLf & varKey
Me.ScheduleDate = Null
End If
End Function
Comment