Limit the number of entries to a table with a specific value (preventing overbooking in airline) (1 Viewer)

Sassaglas12

New member
Local time
Today, 11:19
Joined
Apr 6, 2024
Messages
4
Hi, I am currently working on a small airline management application.
I have a table containing the various technical information about the planes, including their capacity. There is a separate table which contains the flights (time, date, plane used, destination...) and another one containing the bookings (passenger info, what flight are they registered for)

I want to limit the number of entries to the "Bookings" table, so that it is impossible to add more passengers to a flight, than the capacity of the plane used on that flight. ie. I want to prevent overbooking.

Is there a way to do this without using VBA? If not could you suggest how to do it with VBA?
 

bob fitz

AWF VIP
Local time
Today, 10:19
Joined
May 23, 2011
Messages
4,726
You will need some validation code in the forms before update event.
Can you show us your table relationships, or post a copy of the db.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:19
Joined
May 7, 2009
Messages
19,246
Hi, I am currently working on a small airline management application.
was the db done in-house or by a consultant.
you should consider also to contact the programmer and ask him your request.
 

Sassaglas12

New member
Local time
Today, 11:19
Joined
Apr 6, 2024
Messages
4
You will need some validation code in the forms before update event.
Can you show us your table relationships, or post a copy of the db.
Sure
 

Attachments

  • Access_airline_project1.accdb
    4.1 MB · Views: 29
  • WhatsApp Image 2024-04-05 at 22.02.53.jpeg
    WhatsApp Image 2024-04-05 at 22.02.53.jpeg
    30.2 KB · Views: 28

Sassaglas12

New member
Local time
Today, 11:19
Joined
Apr 6, 2024
Messages
4
was the db done in-house or by a consultant.
you should consider also to contact the programmer and ask him your request.
No, it is a case study type project done by myself, nothing corporate. There is no real airline behind it
 

ebs17

Well-known member
Local time
Today, 11:19
Joined
Feb 7, 2020
Messages
1,983
Is there a way to do this without using VBA?
Yes, of course.
The ultimate way is a validation rule in the table (entered in the design view of the table or via code, analogous
Number of bookings per flight is less than or equal to the capacity of the aircraft
 

GPGeorge

George Hepworth
Local time
Today, 02:19
Joined
Nov 25, 2004
Messages
1,992
I don't recall without looking it up. Is it even possible to apply a validation rule to a field in one table based on a value in a field in a different table?
 

bob fitz

AWF VIP
Local time
Today, 10:19
Joined
May 23, 2011
Messages
4,726
Asuming
Assuming that SiegesNom holds the number of seats available before any bookings, you could:
Change the Record Source of frmBooking to
Code:
SELECT tblBooking.BookingID, tblBooking.PassengerID, tblBooking.BaggageNum, tblBooking.FlightID, tblAvion.SiegesNom, tblAvion.SiegesNom FROM tblAvion INNER JOIN (tblFlight INNER JOIN tblBooking ON tblFlight.FlightID = tblBooking.FlightID) ON tblAvion.AvionID = tblFlight.AvionID;
You could then use DCount() function in the forms Current event to return the number of seats already booked and then set the forms Allow Additions property to false when the DCount number is = to SiegesNom.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 04:19
Joined
Feb 28, 2001
Messages
27,321
I don't recall without looking it up. Is it even possible to apply a validation rule to a field in one table based on a value in a field in a different table?

I recalled (and found) an Allen Browne article that includes cross-field validation. But the easiest and clearest way to do this WOULD involve some VBA code in the booking form's BeforeUpdate event.

 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:19
Joined
May 7, 2009
Messages
19,246
try to add some flight numbers and go to booking form.
also see the new query i made.
 

Attachments

  • Access_airline_project1.accdb
    4.5 MB · Views: 28

GPGeorge

George Hepworth
Local time
Today, 02:19
Joined
Nov 25, 2004
Messages
1,992
I recalled (and found) an Allen Browne article that includes cross-field validation. But the easiest and clearest way to do this WOULD involve some VBA code in the booking table's BeforeUpdate event.

Limitations​

You cannot use a validation rule where:

  • You want to call user-defined functions, or VBA functions beyond the ones in JET such as IIf() and Date().
  • The user should be able to bypass the rule.
  • The expression is too complex.
  • The expression involves data in other records or other tables. (Well, not easily, anyway.)
So there may be a complicated way to do it, according to Allen Browne. I'd rather be half right than half fast.
 

ebs17

Well-known member
Local time
Today, 11:19
Joined
Feb 7, 2020
Messages
1,983
I also mentioned a source. Philipp Stiefel (@sonic8) is also very trustworthy.

What always surprises and irritates me is that some VBA coding is preferred to real database work (rules at table level and therefore comprehensive).
You will soon see that unique indexes are no longer used to prevent duplicates or that the use of the set referential integrity is going out of fashion - you can check everything using VBA...

I also find the question about not using VBA with the answer to VBA not very precise, rather answered in the opposite way.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:19
Joined
Feb 19, 2002
Messages
43,484
To begin with, you need to add a column to the flight table to contain the maximum number of passengers for this particular flight. Then, in the BeforeInsert event of the Booking table subform, you count the existing passengers and cancel the BeforeInsert event if the flight is also full.
Code:
If DCount("*", "tblBooking", "FlightID = " & Me.FlightID) >= Me.Parent!SeatCount) then
    Msgbox "This flight is full.  Please try a different one.",vbOKOnly
    Cancel = True
    Me.Undo
    Exit Sub
End If

In the real world, airlines overbook. So, you might want to think about that concept. That would require additional columns in the Booking table to handle the overbooking.
 

isladogs

MVP / VIP
Local time
Today, 10:19
Joined
Jan 14, 2017
Messages
18,261
I have an example app that you can adapt for this purpose:

Related video:
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:19
Joined
May 7, 2009
Messages
19,246
see again the form frmBooking.
booking.png
 

Attachments

  • Access_airline_project1.accdb
    4.5 MB · Views: 27

CJ_London

Super Moderator
Staff member
Local time
Today, 10:19
Joined
Feb 19, 2013
Messages
16,670
I’ve not looked at the requirement in detail but if I was developing this for a client I would be checking a number of other things:
  • How are cancellations to be treated
  • What if some seats are out of commission for repairs
  • What if there are additional crew requiring passenger seats
  • What about special needs requiring extra legroom for example
  • Are there different classes of seats (first/business/economy/etc)
  • Have you considered booking seats rather than just a number
 

Sassaglas12

New member
Local time
Today, 11:19
Joined
Apr 6, 2024
Messages
4
see again the form frmBooking. View attachment 113540
I am very thankful for your aid as well as to all the other contributors! I've fallen terribly ill shortly after writing this post, so please excuse me for the delayed response. Showing the total booked number straight away in the form does seem like a good solution for my use case (it is assumed that the employee of the company will compare the capacity and the nb of reservations).
 

Users who are viewing this thread

Top Bottom