Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / December 2006

Tip: Looking for answers? Try searching our database.

Bookings Integrity.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Simeon Cheeseman - 01 Dec 2006 02:03 GMT
Hi there.

In my database I have a booking system which books people into one of three
'beds'. Now the problem with this is that when the bookings are entered I
have to avoid double bookings. I have looked at allenbrownes query
http://www.allenbrowne.com/appevent.html
It is most useful except that I am not doing it in SQL, Or even if I was I
have to do it programmatically and then from those results decide whether the
person can be booked in and if so which bed they must be in, all in code.
Currently I am using lots of If...Then....Else statements to figure it out.

Thanks
Simeon
Allen Browne - 01 Dec 2006 05:03 GMT
When you are entering a new booking, you don't need to compare every booking
against every other one - just the proposed booking against the others.

You can do that with a DLookup() in the BeforeUpdate event of the form.
Something like this:

Private Sub Form_BeforeUpdate(Cancel As Integer)
   Dim strWhere As String
   Dim varResult As Variant
   Const strcJetDateTime = "\#mm\/dd\/yyyy hh\:nn\:ss\#"

   If IsNull(Me.BookingStart) Or IsNull(Me.BookingEnd) Or IsNull(Me.RoomID)
Or _
       ((Me.BookingStart = Me.BookingStart.OldValue) And _
       (Me.BookingEnd = Me.BookingEnd.OldValue) And _
       (Me.RoomID = Me.RoomID.OldValue)) Then
       'Ignore cases where there was no change, or values are missing.
   Else
       strWhere = "([BookingEnd] < " Format(Me.BookingStart,
strcJetDateTime) & _
           ") AND " & Format(Me.BookingEnd, strcJetDateTime) & _
           " < [BookingEnd]) AND ([RoomID] = " & Me.RoomID & _
           ") AND (BookingID <> " & Me.BookingID & ")"
       varResult = DLookup("BookingID", "BookingsTable", strWhere)
       If Not IsNull(varResult) Then
           If MsgBox("Clashes with booking number " & varResult & vbCrLf &
_
               "Continue anyway?", vbYesNo + vbDefaultButton2) = vbNo Then
               Cancel = True
               'Me.Undo
           End If
       End If
   End If
End Sub

Signature

Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> In my database I have a booking system which books people into one of
> three
[quoted text clipped - 10 lines]
> Thanks
> Simeon
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.