473,322 Members | 1,314 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,322 software developers and data experts.

MS ACCESS Relationship and Duplicate

Hi,

I have ms access database with two tables connected by "ID Number" as primary using a one-to-many relationship. My question is how can i create a code or something like that , that would notify me about duplicate entry.

for ex:

table 1 with ID number, name, address
connected with relationship
table 2 with ID number, date, remarks

entry 1

ID number | name | address | date | remarks

00-1 | Nat | California | 1-14-14 | present
00-2 | Rea | California | 1-14-14 | present

entry 2

ID number | name | address | date | remarks

00-1 | Nat | California | 1-15-14 | present
00-2 | Rea | California | 1-14-14 | present


Note: if i do enter same date in id-number 00-2 it should give me a note that it was or it is a duplicate entry.

need help..correction about my question is accepted
Feb 26 '14 #1
4 1394
ADezii
8,834 Expert 8TB
Assuming the [ID Number] Field in Table1/Table2 is TEXT, then
Expand|Select|Wrap|Line Numbers
  1. If DCount("*","Table2","ID Number = '" & <ID to Test> & "'") > 0 Then
  2.   'ID already exists in Table1, a Duplicate
  3. End If
Feb 26 '14 #2
Rabbit
12,516 Expert Mod 8TB
There's no code needed. Use a composite primary key if you don't already have a key on that table. Otherwise, use a composite unique index.
Feb 26 '14 #3
You will not get duplicates if you make the key in the second table consist of the ID and the date. Then when you enter the data in the second table, it will not allow you to enter a second record with the same ID and date.

If you are just trying to find duplicates in the second table, do a Find Duplicates query.
Feb 27 '14 #4
ADezii
8,834 Expert 8TB
You can easily create a Unique, Composite Index on the [ID] and [Date] Fields but a Duplication Error that is generated will be cryptic and confusing to the User. In the additional to the Index, and assuming you are manipulating the Data via a Form, code in the BeforeUpdate() Event of the Form can easily check for Duplication, provide a more meaningful Error Message, and Cancel the Update of the Form. The Index would still be in place as a secondary measure. An example of an Error Message using this approaqch would be:
Expand|Select|Wrap|Line Numbers
  1. An entry for ID: [00-2] and Date: [1/1/2014] already exists and cannot be duplicated
Code Example:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If DCount("*", "Table2", "[ID Number] = '" & Me![txtIDNumber] & _
  3.           "' AND [Date] =#" & Me![txtDate] & "#") > 0 Then
  4.   MsgBox "An entry for ID: [" & Me![txtIDNumber] & "] and Date: [" & Me![txtDate] & _
  5.          "] already exists and cannot be duplicated", vbExclamation, "Record Duplication"
  6.     Cancel = True
  7. End If
  8. End Sub
Feb 27 '14 #5

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

Similar topics

17
by: Jelmer | last post by:
Hi, I am mildly familiar with ms access developement and I have been asked to port and document a ms access app. I expect the porting (97 to XP) to be fairly straightforward. However documenting...
3
by: Bari Allen via AccessMonster.com | last post by:
I have a database in a Front-End/Back-End User Environment, which has been running fine, for 4 years. Lately, when the users try to enter data (from a form into a single table) they've been...
5
by: Steve B. | last post by:
A particular column in my Access DB table, and the associated datagrid, cannot have duplicate string entries. I've selected "Yes (no duplicates)" for the Indexed Field Property of this column in...
5
by: BrianDP | last post by:
This is a strange one-- I have an Access 2K database with a split front end/back end. There are two tables in the back end - RFile and RLine. There is a one to many relationship from...
1
by: 2D Rick | last post by:
Access2003 in XP If I open a form to a specific record and click on a command button with the following code I get a duplcate record: DoCmd.RunCommand acCmdSelectRecord DoCmd.RunCommand...
19
by: MooseManDan | last post by:
This is a very nice site and I'd like to say thank you to the mdoerators and site administrator for maintaining. This is my first post; I hope someone can assist. I'm working on a database for my...
1
by: chriscarllewis2012 | last post by:
Hey - I'm designing the relationships between some tables in Access and am looking for a little guidance - The part I'm struggling with: I have four tables, Inspections...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
4
by: shodan | last post by:
Hi board, I'm using excel vba to drive my access database. Now I encountered the following problem: I have an update qry to update a table which has an index field. Because of this, I always...
5
by: lawson | last post by:
In access 2003, how do I repeat the same data in different tables without typing it out again. That in another table with different name.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.