Access Duplicate Records

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I need some suggestions.

I have a Form that will add records to a table.
These are the fields that will need to be filled using the form:
Entered By
Date Entered
Cycle Month
Report Type
Date Reviewed
Reviewer Type
Reviewer
Reviewer Report Area
Main Section
Topic Section
Ownership-Individual
Ownership-Team
Count
Priority
Approved By
L1 (Quality Category L1)
L2 (Quality Category L2)
L3 (Quality Category L3)
Other (If Other is selected in L3)
Repeat Ask (check box)
Exception (check box)
Notes
Outliers
Additional Outliers

I have a RefID column that is an auto-generated number.
I need to ensure that when a record is added that it is not being duplicated. However, based on the columns mentioned above, there is no customer name or account number that will make this task easy to ensure that there are no duplicates.
In looking at each column, they can be duplicate in of itself, but the entire row cannot be the same.
How can I ensure there will be no duplicates added to the table by checking if all columns are the same?


Thank you
 
Last edited:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
if you concatenate the columns, then before allowing the post concatenate the input and have it sent to not allow duplicates. Use only values that are exact but unique, so additional outliers as maybe a text field with no defined format should not be used, dates, owners etc are in unless free text
 
Upvote 0
I think you need to normalize your table (and remove the spaces from field names). That will reduce the number of fields on the table and will make validation easier.

Tbh I think you may be fighting a losing battle trying to make these unique, for example the chances of someone putting exactly the same thing into a Notes field as someone else is extremely small
 
Upvote 0
Mole 999, so you're suggesting to concatenate all fields that are not free text, correct?

Kyle123, I was afraid that I might be fighting a losing battle here, lol
 
Upvote 0
Mole 999, so you're suggesting to concatenate all fields that are not free text, correct?

Kyle123, I was afraid that I might be fighting a losing battle here, lol

or enough that will give you a unique key to compare against and achieve your aim
 
Upvote 0
Ok, I will try your suggestion and will let you know how it works out.
 
Upvote 0
Just for the record it isn't precisely necessary to concatenate fields. Just that each field (which shouldn't be duplicated) isn't duplicated.

For example, if a record is:
1, 'abc', 'def'

you can check:
Code:
insert into MyTable values (2, 'abc','def') 
    where not exists (select * from MyTable where F2 = 'abc' and F3 = 'def')

or you can check:
Code:
insert into MyTable values (2, 'abc','def') 
    where not exists (select * from MyTable where F2 & F3 = 'abcdef')

In either case, nulls are a special case that must be handled appropriately (not shown here!) and in the latter case make sure you are assuming the right things about how conversions from non-text to text will occur (since you want to compare a concatenated string to a concatenated string).
 
Last edited:
Upvote 0
Hello,

I am back to this issue. My brain must be fried at this point because I cannot make sense as to how to check if the record being added has already been added to the table.

I have the below so far, but can't seem to get a code started for checking if ConcatFormValues = ConcatTableFields then msgbox "Record has already been added".

Code:
Private Sub Form_AfterUpdate()

Dim ConcatTableFields As String
Dim ConcatFormValues As String
Dim strDupe As String

ConcatTableFields = [EnteredBy] & " " & [DateEntered] & " " & [CycleMonth] & " " & [ReportType] & " " & [DateReviewed] & " " & [ReviewerType] & " " & [Reviewer] & " " & [ReviewerReportArea] & " " & [MainSection] & " " & [TopicSection] & " " & [OwnershipIndividual] & " " & [OwnershipTeam] & " " & [Count] & " " & [Priority] & " " & [ApprovedBy] & " " & [L1] & " " & [L2] & " " & [L3] & " " & [RepeatAsk] & " " & [Exception] & " " & [Hyperlink]
ConcatFormValues = Me.EnteredBy & " " & Me.DateEntered & " " & Me.CycleMonth & " " & Me.ReportType & " " & Me.DateReviewed & " " & Me.ReviewerType & " " & Me.Reviewer & " " & Me.ReviewerReportArea & " " & Me.MainSection & " " & Me.TopicSection & " " & Me.Individual & " " & Me.Team & " " & Me.txtCount & " " & Me.PriorityLevel & " " & Me.Approved & " " & Me.L1 & " " & Me.L2 & " " & Me.L3 & " " & Me.Repeat & " " & Me.Exception & " " & Me.txtHyperlink


The reason I am doing it this way is because each field by itself can be duplicated. I need to know that the entire record being added has not already been added. Hopefully I didn't confuse anyone and hopefully I'm not overcomplicating an easy task :)
 
Upvote 0
I would not do this with concatenation personally.
Just use regular fields in your sql.

For instance, to check if a record exists Table1 with values (1,2,3) for the first three fields, just:
Code:
select * from Table1 
where Field1 = 1
and Field2 = 2
and Field3 = 3

As alluded to, an index that excludes duplicates would also work (insertion would fail).
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,737
Members
449,050
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top