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
4 1394
Assuming the [ID Number] Field in Table1/Table2 is TEXT, then - If DCount("*","Table2","ID Number = '" & <ID to Test> & "'") > 0 Then
-
'ID already exists in Table1, a Duplicate
-
End If
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.
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.
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: -
An entry for ID: [00-2] and Date: [1/1/2014] already exists and cannot be duplicated
Code Example: -
Private Sub Form_BeforeUpdate(Cancel As Integer)
-
If DCount("*", "Table2", "[ID Number] = '" & Me![txtIDNumber] & _
-
"' AND [Date] =#" & Me![txtDate] & "#") > 0 Then
-
MsgBox "An entry for ID: [" & Me![txtIDNumber] & "] and Date: [" & Me![txtDate] & _
-
"] already exists and cannot be duplicated", vbExclamation, "Record Duplication"
-
Cancel = True
-
End If
-
End Sub
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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.
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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...
| |