If Exist function in Access.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can i make it so that if i try and enter data that is already entered, then i
does not allow me to save the record.
For example for a booking system.
Is there a solution?
 
The best way to do this is to create a unique index in your table.

Example: if you are booking rooms for a date, your Booking table will have:
BookingDate the date being booked.
RoomID unique code for the room.
To prevent duplicate bookings for the same room and date:
1. Open the Booking table in design view.

2. Open the Index box (View menu.)

3. Enter a name into the first column of the dialog, and the first field
beside it. In the lower pane, set Unique to Yes. On the next row of the
dialog, leave the name, blank, and choose the other field in the 2nd column.
Your dialog will now look something like this:
BookingdateRoomid BookingDate Ascending
RoomID Ascending

4. Save the changes.

Access won't allow duplicates now.

The other alternative is to cancel the BeforeUpdate event of the form if
there is a duplicate, but that is best reserved for cases where you want to
warn of a duplicate, but allow it to occur anyway.
 
What i have is a systme that has where you book a single room on a certain
date. The option is to have a certain time. What i need to validate is that
you cannot have certain time period on a certain date. The room cannot be
booked twice on the same date.
Is there a way to do it now. I already have two tables, 1 is a booking
table, the other is a customer table, both are linked, so that the main form
is a main customer form. There is the subform that shows bookings done by
that customer.
Can you help now? I don't really want to have to change the forms. or the
tables.
Thanks
 
x5/315 said:
Can you help now? I don't really want to have to change the forms. or the
tables.

I guess the extended answer I gave you was of no use then, if you want the
functionality but you don't want to change anything in your forms or tables.
 
Back
Top