Since one can't tell the user that "Date2 is wrong!" you should find
something more descriptive. Here's an example where the check in date and
time must be later than the checkout date and time. BTW, one can use a
Date/Time field to store both the date and the time, but if they need to be
separated for display purposes, then the DateValue( ) and TimeValue( )
functions can be used.
Private Sub ChkInDate_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrHandler
If (Me!ChkInDate.Value < Me!ChkOutDate.Value) Then
MsgBox "You cannot check in the item" & vbCrLf & _
"before you check it out!", vbCritical + vbOKOnly, "Invalid Date!"
Cancel = True
End If
Exit Sub
ErrHandler:
MsgBox "Error in ChkInDate_BeforeUpdate( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
Private Sub ChkInTime_BeforeUpdate(Cancel As Integer)
On Error GoTo ErrHandler
If (Me!ChkInTime.Value < Me!ChkOutTime.Value) Then
If (Me!ChkInDate.Value <= Me!ChkOutDate.Value) Then
MsgBox "You cannot check in the item" & vbCrLf & _
"before you check it out!", vbCritical + vbOKOnly, _
"Invalid Date And Time!"
Cancel = True
End If
End If
Exit Sub
ErrHandler:
MsgBox "Error in ChkInTime_BeforeUpdate( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
HTH.
Gunny
See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
> Hi all,
>
[quoted text clipped - 10 lines]
> enter the wrong date or time. I need some type of code for Date2 and Time2.
> How can I code this? Thanks
bladelock - 25 Oct 2005 19:37 GMT
You're very smart, thank you.
> Since one can't tell the user that "Date2 is wrong!" you should find
> something more descriptive. Here's an example where the check in date and
[quoted text clipped - 78 lines]
> > enter the wrong date or time. I need some type of code for Date2 and Time2.
> > How can I code this? Thanks
'69 Camaro - 25 Oct 2005 20:51 GMT
You're very welcome. And thanks, but it's just a matter of "been there,
done that" a few times, so you'll find these solutions easy to come by after
you've worked with Access for a while.
Gunny
See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.
> You're very smart, thank you.
>
[quoted text clipped - 91 lines]
>> > Time2.
>> > How can I code this? Thanks