Validating for Dates

  • Thread starter Thread starter Tara via AccessMonster.com
  • Start date Start date
T

Tara via AccessMonster.com

Hey There,

I am newer to the whole Access database environment and am trying to create
a VBA statement that will display a textbox to the user when they enter a
date into the booking Date field tht already exists. It is an event
database and we can't have more than one event on the same date. I have
been playing with the Dlookup function but can't seem to get it to work.

This is what I had:

Private Sub txtBookingDate_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("BookingDate", "tblBookings", "BookingDate=" &
Me.BookingDate)) Then
MsgBox "There is already a booking on that Date!"
Cancel = True
End If

End Sub

Am I completely off base?

Many Thanks,

Tara
 
Private Sub txtBookingDate_BeforeUpdate(Cancel As Integer)
with currentdb.openrecordset("select BookingDate from tblBooking where
BookingDate=#" & me.BookingDate & "#"
if not .eof then
MsgBox "There is already a booking on that Date!"
cancel=true
end if
.close
end with
end sub

Note that it may be better to check for date range instead, otherwise
you may not always get the desired results, ie #1/1/2005# is not the same as
#1/1/2005 00:00.001#
 
Back
Top