HI,
I have this function MultiCover which may be useful. You supply it a
recordset made up of the start and
end times of the intervals as separate records. You could make this with a
union query.
SELECT dtmStartTime as dbl, 1 as Ev FROM mytimes UNION SELECT dtmEndTime as
dbl, -1 as Ev FROM mytimes ORDER BY dbl
Then, if there was any overlap between your form and the database records
you'd have
MultiCover(rs, Form!myform!dtstart, Form!myform!dtEnd)>0.
nMin, nMax are just min and max functions, something like
Public Function Min(ParamArray la() As Variant) As Variant
Dim l As Long
If UBound(la) = 0 Then Min = Null: Exit Function
Min = la(0)
For l = 1 To UBound(la)
Min = IIf(la(l) < Min, la(l), Min)
Next l
End Function
Note it doesn't set rs=nothing because I used the rs elsewhere - its
probably better for you to define the rs inside the function and pass SQL in
your case.
Public Function MultiCover(rs As DAO.Recordset, Optional ClipLo, Optional
ClipHi) As Double
'Finds cover of set of intervals between optional clipping
'rs: set of period start/stop events format !dbl (ASC),!Ev {1,-1)
Dim dblStart As Double, lStarts As Long, dblClipLo As Double, dblClipHi As
Double
dblClipLo = IIf(IsMissing(ClipLo), DBL_MIN, CDbl(ClipLo))
dblClipHi = IIf(IsMissing(ClipHi), DBL_MAX, CDbl(ClipHi))
If (IsMissing(ClipLo) Or IsMissing(ClipHi)) Then
Else
If dblClipHi < dblClipLo Then dblStart = dblClipHi: dblClipHi =
dblClipLo: dblClipLo = dblStart 'Swap
End If
With rs
If Not .BOF Then .MoveFirst
Do While Not .EOF
If !ev > 0 Then
If lStarts = 0 Then dblStart = nMin(nMax(!dbl, dblClipLo), dblClipHi)
lStarts = lStarts + 1
Else
lStarts = lStarts - 1
If lStarts = 0 Then MultiCover = MultiCover + nMax(nMin(!dbl,
dblClipHi), dblClipLo) - dblStart
End If
.MoveNext
Loop
End With
End Function
Well its one idea maybe wait for something better from the MVP's.
Regards