472,351 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 software developers and data experts.

Booking database

I am trying to construct an Access database to be used for making bookings
to share vehicles. The user has to be able to select a starting date and
time and an ending date and time. However, when the user tries to select a
period already booked the system needs to object and not allow it. Any ideas
how this can be achieved?

Mike Glazer
Nov 13 '05 #1
2 2751
Use the BeforeUpdate event of the form to run the check and see if this
vehicle is already booked.

You can do that with a DLookup() if you get the Criteria argument right.

The basic idea is that there is a clash between event A and event B if:
A starts before B ends, and
B starts before A ends, and
they are both for the same vehicle.

--
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.

"Mike Glazer" <gl****@physics.ox.ac.uk> wrote in message
news:d6**********@news.ox.ac.uk...
I am trying to construct an Access database to be used for making bookings
to share vehicles. The user has to be able to select a starting date and
time and an ending date and time. However, when the user tries to select a
period already booked the system needs to object and not allow it. Any
ideas how this can be achieved?

Nov 13 '05 #2
"Mike Glazer" <gl****@physics.ox.ac.uk> wrote in message news:d6**********@news.ox.ac.uk...
I am trying to construct an Access database to be used for making bookings
to share vehicles. The user has to be able to select a starting date and
time and an ending date and time. However, when the user tries to select a
period already booked the system needs to object and not allow it. Any ideas
how this can be achieved?

Mike Glazer



The following is a rather simplified example, which I'm sure will set you on the right track:

Create a table named v_Book with the following fields:
Book_ID (Autonumber, Incremental)
Vehicle_ID (Text)
Date_Time_Out (Date/Time)
Date_Time_In (Date/Time)
Cancelled (Yes/No)

Paste the following code into a new module:

--------------------------------------------------------------------------------

Public Function BookID(VehicleID As String, DateOut As Date, DateIn As Date) As Long

If DateOut >= DateIn Then
MsgBox "Date In must be greater than Date Out", vbExclamation
Exit Function
End If

Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("SELECT v_Book.* " _
& "FROM v_Book " _
& "WHERE v_Book.Vehicle_ID='" & VehicleID & "' " _
& "AND v_Book.Cancelled=False " _
& "AND ((v_Book.Date_Time_Out<#" & DateOut & "# AND v_Book.Date_Time_In>#" & DateOut & "#) " _
& "OR (v_Book.Date_Time_Out<#" & DateIn & "# AND v_Book.Date_Time_In>#" & DateIn & "#)) " _
& ";")

If rs.RecordCount Then
MsgBox "Vehicle: " & VehicleID & vbNewLine _
& "is already booked" & vbNewLine _
& "from " & rs!Date_Time_Out & vbNewLine _
& "to " & rs!Date_Time_In
rs.Close
Exit Function
End If
rs.Close

Set rs = CurrentDb.OpenRecordset("v_Book", dbOpenDynaset)
rs.AddNew
rs!Vehicle_ID = VehicleID
rs!Date_Time_Out = DateOut
rs!Date_Time_In = DateIn
BookID = rs!Book_ID
rs.Update
rs.Close

Set rs = Nothing

End Function

--------------------------------------------------------------------------------

To test this code, try the following from the Debug window:
?BookID("CS10",#5/16/2005 6:00:00 PM#,#5/17/2005 12:00:00 PM#)
The result should be a Long Integer with the Booking ID.

Now try:
?BookID("CS10",#5/17/2005 11:59:00 AM#,#5/17/2005 12:00:00 PM#)
Because the DateOut is in between the DateOut and DateIn of an already existing booking which has not been cancelled, you should get a MessageBox stating:
Vehicle: CS10
is already booked
from 5/16/2005 6:00:00 PM
to 5/17/2005 12:00:00 PM

See if this method works for you.
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: PaulD | last post by:
Can anyone point me in the direction of a sample Access booking system? Trying to build a booking system were customers can book a computer by date...
4
by: Grant | last post by:
Hi I have a database which logs the usage of rooms. Some booking are entered well in advance, and some have stays of more than six months. I...
4
by: WiseOwl | last post by:
Hi folks I teach. At school, four IT rooms are booked using a paper based outline timetable. Completing it is easy but basic and impossible to...
2
by: Andy | last post by:
Hi folks I teach. At school, four IT rooms are booked using a paper based outline timetable. Completing it is easy but basic and impossible to...
2
by: MarcusB | last post by:
Hi, At our place we have Video Projector which people use to book. So far we have on paper booking system. I need some help in writing asp (web...
25
by: NDayave | last post by:
How do, I have a access 2000 booking database with Personal Details, Outing Details and the Bookings in three tables: tblBookings --...
5
by: Armenante | last post by:
Hi, I am creating a database for my A level project and i am stuck on the validation for the booking part of the database, and was just wondering...
3
by: Wildster | last post by:
Hi, I have a form in Access 2000 running Windows XP with the following fields: - Booking_ID Date Person_Name Booking_Type 8-9am (y/n...
3
by: 88stevie | last post by:
Hi all, I have a system and I'm a little stuck. It's a booking system. It has rooms, etc and every room have a daily price. Then it has...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.