If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
3 fields together unique/no duplicates?
Is it possible to make a combination of 3 fields be unique? I know you can
have the ID (autonumber) be unique or have a field set to be indexed and not allow duplicates but I need to use 3 fields. My scenario is a table (tblPeople) with Fname, Lname and postcode. I do not want any duplicate people in my tblPeople. They all have multiple linked records in tblProjects. The problem is that someone doing data entry keeps creating duplicate people entries when they exist already. Can I set these 3 to be unique together? Not as individual uniques. Would it be easier to make a field in the tblPeople that is a combination of Fname Lname Postcode and that be unique? Then on the form it would use some code to make the combination entered into that field. I could run a query to make the 3000+ records have that combination field so its all up to date. What is my best approach? Any help or thoughts are appreciated. Many thaks. JBowler |
#2
|
|||
|
|||
J.,
No need to use an extra field for concatenation, just open your table in design view, select all three fields (by clicking on the little grey button to the left of each field name while holding down Ctrl), and click on the Primary Key tool button on the toolbar. This will create a composite PK that will only allow unique combinations of the three field entries. Note: this is an easy way to do it, but not necessarily the best design. Ideally, you would use an autonumber PK field in tblPeople, which would make joins to other tables much more efficient, and employ some other method to avoid double entries, e.g. use a macro or some code in the Before Update event of the data entry form to look for double entries. Alternartively, you could stick with the composite PK on the three fields to prevent duplicates, but still use an (indexed) autonumber field for joining with other tables. HTH, Nikos "JBowler" wrote in message ... Is it possible to make a combination of 3 fields be unique? I know you can have the ID (autonumber) be unique or have a field set to be indexed and not allow duplicates but I need to use 3 fields. My scenario is a table (tblPeople) with Fname, Lname and postcode. I do not want any duplicate people in my tblPeople. They all have multiple linked records in tblProjects. The problem is that someone doing data entry keeps creating duplicate people entries when they exist already. Can I set these 3 to be unique together? Not as individual uniques. Would it be easier to make a field in the tblPeople that is a combination of Fname Lname Postcode and that be unique? Then on the form it would use some code to make the combination entered into that field. I could run a query to make the 3000+ records have that combination field so its all up to date. What is my best approach? Any help or thoughts are appreciated. Many thaks. JBowler |
#3
|
|||
|
|||
In addition to what Nikos has said, you will probably want to reconsider
your plan a bit. Do you suppose that it's possible for 2, or more, John Smiths to live in the same Postal Code? You could possibly encounter a situation where 2, or more, John Smiths live at the same street address, use the same telephone number, etc. In most cases, it will take more than the 3 fields you suggested to guarantee a unique record. -- Lynn Trapp MS Access MVP www.ltcomputerdesigns.com Access Security: www.ltcomputerdesigns.com/Security.htm "JBowler" wrote in message ... Is it possible to make a combination of 3 fields be unique? I know you can have the ID (autonumber) be unique or have a field set to be indexed and not allow duplicates but I need to use 3 fields. My scenario is a table (tblPeople) with Fname, Lname and postcode. I do not want any duplicate people in my tblPeople. They all have multiple linked records in tblProjects. The problem is that someone doing data entry keeps creating duplicate people entries when they exist already. Can I set these 3 to be unique together? Not as individual uniques. Would it be easier to make a field in the tblPeople that is a combination of Fname Lname Postcode and that be unique? Then on the form it would use some code to make the combination entered into that field. I could run a query to make the 3000+ records have that combination field so its all up to date. What is my best approach? Any help or thoughts are appreciated. Many thaks. JBowler |
#4
|
|||
|
|||
We considered that but in the UK a postcode is limited to very few
households. The chance exists but is rare. I dont have any other fields that can be part of a unique. I will go with the advice and keep this in mind. Many thanks for your help. James "Lynn Trapp" wrote in message ... In addition to what Nikos has said, you will probably want to reconsider your plan a bit. Do you suppose that it's possible for 2, or more, John Smiths to live in the same Postal Code? You could possibly encounter a situation where 2, or more, John Smiths live at the same street address, use the same telephone number, etc. In most cases, it will take more than the 3 fields you suggested to guarantee a unique record. -- Lynn Trapp MS Access MVP www.ltcomputerdesigns.com Access Security: www.ltcomputerdesigns.com/Security.htm "JBowler" wrote in message ... Is it possible to make a combination of 3 fields be unique? I know you can have the ID (autonumber) be unique or have a field set to be indexed and not allow duplicates but I need to use 3 fields. My scenario is a table (tblPeople) with Fname, Lname and postcode. I do not want any duplicate people in my tblPeople. They all have multiple linked records in tblProjects. The problem is that someone doing data entry keeps creating duplicate people entries when they exist already. Can I set these 3 to be unique together? Not as individual uniques. Would it be easier to make a field in the tblPeople that is a combination of Fname Lname Postcode and that be unique? Then on the form it would use some code to make the combination entered into that field. I could run a query to make the 3000+ records have that combination field so its all up to date. What is my best approach? Any help or thoughts are appreciated. Many thaks. JBowler |
#5
|
|||
|
|||
"JBowler" wrote in news:uX3RFa9nEHA.1712
@tk2msftngp13.phx.gbl: We considered that but in the UK a postcode is limited to very few households. The chance exists but is rare. Don't believe it. Fathers often give their names to their sons (and mothers to daughters) so it is going to be more-than-averagely likely for the same name to be present at the same address. The existence of nulls (what, you mean you never, ever, don't know the postcode?) will complicate matters further. By all means have your form check for likely clashes (for example, use the Form_BeforeUpdate event) but using the db engine to prevent them is going to lead to very disgruntled users, not to say the data subjects. Hope that helps Tim F |
#6
|
|||
|
|||
Don't believe it. Fathers often give their names to their sons (and
mothers to daughters) so it is going to be more-than-averagely likely for the same name to be present at the same address. Exactly. My father and my older brother were both named Robert Trapp and lived at the same address until my brother went to college. Adding a middle initial to the mix would have distinguished them, but that wouldn't always be the case. It happens all the time. -- Lynn Trapp MS Access MVP www.ltcomputerdesigns.com Access Security: www.ltcomputerdesigns.com/Security.htm |
#7
|
|||
|
|||
On Tue, 21 Sep 2004 11:57:47 +0100, "JBowler" wrote:
Is it possible to make a combination of 3 fields be unique? I know you can have the ID (autonumber) be unique or have a field set to be indexed and not allow duplicates but I need to use 3 fields. My scenario is a table (tblPeople) with Fname, Lname and postcode. How would your table handle Fred Brown, postcode 83660, and his son Fred Brown, postcode 83660? Names ARE NOT UNIQUE, even within a household, much less a postcode. I do not want any duplicate people in my tblPeople. They all have multiple linked records in tblProjects. The problem is that someone doing data entry keeps creating duplicate people entries when they exist already. Can I set these 3 to be unique together? Not as individual uniques. Certainly. You can include up to ten fields in a Primary Key - ctrl-mouseclick the fields and then click the key icon. Would it be easier to make a field in the tblPeople that is a combination of Fname Lname Postcode and that be unique? No. This is redundant, inefficient, and unnecessary! Then on the form it would use some code to make the combination entered into that field. I could run a query to make the 3000+ records have that combination field so its all up to date. What is my best approach? Any help or thoughts are appreciated. Many thaks. I'd say the best approach is to use the BeforeUpdate event of the Form in which the user is entering data to check for duplicates. Something like: Private Sub Form_BeforeUpdate(Cancel as Integer) Dim vFound As Variant vFound = DLookUp("PersonID", "your-table-name", "[FName] = """ & _ Me!txtFName & """ AND LName = """ & Me!txtLName & _ """ AND PostCode = '" & Me!txtPostCode & "'") If Not IsNull(vFound) Then MsgBox "This person's name already exists. Proceed anyway?", _ vbYesNo) If iAns = vbNo Then Cancel = True End If End Sub or you can get fancier and give the user the option of viewing the existing record. John W. Vinson[MVP] Join the online Access Chats Tuesday 11am EDT - Thursday 3:30pm EDT http://community.compuserve.com/msdevapps |
#8
|
|||
|
|||
James,
Regrettably, all above holds true, no question you'll hit duplications sooner or later, it's just a matter of time. It's no coincidence the best practice on the subject in the US is the use of the Social Security Number as a PK. Don't you have something similar in the UK, like an NHS registration number or something, assigned to a person virtually at birth? It would be the perfect solution (Access can't handle DNA signatures yet!). Nikos "Lynn Trapp" wrote in message ... Don't believe it. Fathers often give their names to their sons (and mothers to daughters) so it is going to be more-than-averagely likely for the same name to be present at the same address. Exactly. My father and my older brother were both named Robert Trapp and lived at the same address until my brother went to college. Adding a middle initial to the mix would have distinguished them, but that wouldn't always be the case. It happens all the time. -- Lynn Trapp MS Access MVP www.ltcomputerdesigns.com Access Security: www.ltcomputerdesigns.com/Security.htm |
#9
|
|||
|
|||
All,
We've missed one more possibility: misspellings. Take a look at my surname and try to guess how many different spellings of it I've seen over the years, then multiply by ten to be closer! How many records would I get? Nikos "Lynn Trapp" wrote in message ... Don't believe it. Fathers often give their names to their sons (and mothers to daughters) so it is going to be more-than-averagely likely for the same name to be present at the same address. Exactly. My father and my older brother were both named Robert Trapp and lived at the same address until my brother went to college. Adding a middle initial to the mix would have distinguished them, but that wouldn't always be the case. It happens all the time. -- Lynn Trapp MS Access MVP www.ltcomputerdesigns.com Access Security: www.ltcomputerdesigns.com/Security.htm |
#10
|
|||
|
|||
"Nikos Yannacopoulos" wrote in
: Don't you have something similar in the UK, like an NHS registration number or something, assigned to a person virtually at birth? Yes but... It is forbidden to use them for linking outside the health service, even to store them on non-NHS systems Anyway, nobody knows their number Anyway, they are not duplicate-free (but what do you expect from Government IT systems?)... We also have National Insurance Numbers but they are not widely used outside the taxation/ employment spheres, for reasons similar to above. All the best Tim F |
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How are duplicates suppressed? | Sam Hobbs | Setting Up & Running Reports | 3 | September 3rd, 2004 03:12 AM |
Optional Merge Fields | Pete Bennett | Mailmerge | 4 | August 25th, 2004 11:03 AM |
"UNION" Query with different fields in the two tables | Dkline | Running & Setting Up Queries | 5 | July 30th, 2004 09:05 PM |
Lookup fields on label report | Howard | Setting Up & Running Reports | 1 | June 3rd, 2004 02:43 AM |