473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Checking Composite Key Duplicates

Mary... anyone... can someone help me?

I have used Mary's excellent sample code to check for the existence of a duplicate primary key and give the user an improved feedback (well, better than the Access default one!).

What I'd like to know, is that if the 'primary key' is in fact composite from three fields, e.g. appointment_date, appointment_time and gp_id, then how can we code a solution to detect a gp has been double-booked for example, and then return a custom message box?

Thank you so much in advance,

AndyCash
Oct 9 '10 #1
5 2987
nico5038
3,080 Expert 2GB
For this we create in general a unique index consisting of these three fields. Thus Access will block dupes (and Null values). The raised error can be intercepted with an On ERROR and communicated to the user.
Another option is to check the combination after entering all fields with e.g. a DCOUNT() to check or 1 is returned..

Nic;o)
Oct 9 '10 #2
NeoPa
32,556 Expert Mod 16PB
Andy, You're being unclear. Are you looking for a way to avoid duplicates, or a way to detect them?

The composite PK will ensure none is added. Detecting dodgy data within a dataset is another matter, and can be done using a SQL query. If you need further help then you'll need to be clearer about what details you're working with.
Oct 9 '10 #3
Hi NeoPa,

Sorry! What I am trying to do is this:

I am creating an appointments database for a local hairdressers. I have one table for 'Regular Customers' with CustID as PK. I have another table for 'Stylists' with StyID as PK. Both these PKs are foreign keys in an 'Appointments' table.

In the 'Appointments' table, to keep each appointment unique and prevent double bookings, I have ApptDate, ApptTime and StyID as composite keys.

This works fine in preventing a stylist from being booked in twice on the same day and time.

However, should the end user accidently book in a duplicate appointment, naturally Access returns its own error message. What I would like to learn, is what do I need to do within my database, to override this error message and return a custom error message that is more user friendly, e.g. "This stylist already has an appointment on this day and time. Please amend".

Thank you to anyone who can help give me the solution... I do appreciate it in advance.

AndyCash
Oct 10 '10 #4
nico5038
3,080 Expert 2GB
I would try to prevent his by showing e.g. a bar with the "booked" time(s) of the stylist.
Just mimic the Outlook agenda with the appointments visible per day/week...

Idea ?

Nic;o)
Oct 10 '10 #5
NeoPa
32,556 Expert Mod 16PB
You could check out Custom Error Messages as one option.

Nico's idea wouldn't hurt too. It never hurts to give the operator more information, especially when this can help to avoid mishaps.

Lastly, you could check the dataset first (using DLookup()) in the Form_BeforeInsert() event procedure and throw up your own MsgBox() message if the composite key already exists.
Oct 11 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Alexander Anderson | last post by:
I have a DELETE statement that deletes duplicate data from a table. It takes a long time to execute, so I thought I'd seek advice here. The structure of the table is little funny. The following is...
1
by: Spockie | last post by:
I do not use linkedlist stdlibrary, vector i make my own, but i have problems with one issue, and that is checking if there are duplicates in the middle of inputing information line 294 ...
1
by: keys4worship | last post by:
Situation: Day 1 Table contains 100 items of actions imported via FTP. One of the fields in the table can be updated to reflect an assigned unit code. Day 2 Actions that may be duplicates of...
5
by: John | last post by:
Specifically for joint tables... tblStudents tblClasses tblClasses_Students Is it be good programming to use a composite primary key in tblClasses_Students (where the key is ClassID and...
18
by: Thomas A. Anderson | last post by:
I am a bit confused in creating a composite primary key. I have three table with two of the tables containing primary keys. I have two of the tables (each with a primary key) having one to many...
1
by: AndyB | last post by:
I have found a lot of material on removing duplicates from a list, but I am trying to find the most efficient way to just check for the existence of duplicates in a list. Here is the best I have...
2
by: oaklander | last post by:
I currently have two String variables I check to find if they are duplicates: String str1 = "red"; String str2 = "yellow"; if (str1.equals(str2)){ System.out.println("Duplicate"); }...
2
by: lostdawg | last post by:
Hi, I have a question regarding duplicate entries. Basically I have a simple database with a main table called contacts. This table has 2 fields, contactsid and contactsnum. The main form has a...
3
by: staja84f | last post by:
I'm trying to locate duplicate data in a table using 4 columns: employee_id (primary key), employeeid, lastname and firstname. I can pull up the duplicate data with the last three listed columns,...
7
by: john.cole | last post by:
I have searched all the groups I can, and I still haven't been able to come up the solution I need. I have the following problem. In my form named sbfrmSpoolList, I am entering a job, spool and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.