Avatar of Marilyn
Marilyn
 asked on

Check for duplicates in Microsoft Access VBA

I import a CSV file into a temporary table ("Import") in VBA.  The file may contain duplicate records (product number), I don't want to import the duplicate records I want to display a message showing for the user to select 1 of the duplicate records to keep (fields to display:  Account Name, Account Number, Opportunity Id, Product Number, price, quantity, total).  The record they do not choose should be deleted and the process should continue

Here is my code for the import:

Public Function Import_Quote_Test()
Dim strFilter As String
Dim strImportFileName As String
Dim DB As DAO.Database
Dim strSQL As String
Dim strQuoteNo As String
Dim rstImport As DAO.Recordset
Dim strResponse As String
Dim ctl As Control

On Error GoTo Import_Quote_Test_Err

Set DB = CurrentDb

'Prompt user to select Import File

strFilter = ahtAddFilterItem(strFilter, "Import Files", "*.csv")
strCreateFileName = ahtCommonFileOpenSave( _
                Filter:=strFilter, OpenFile:=True, _
                DialogTitle:="Please select an import file...", _
                Flags:=ahtOFN_HIDEREADONLY)

'Make sure the Import File Name is not blank
If strCreateFileName = "" Then
    MsgBox ("Import file not selected, please try again.")
    GoTo Import_Quote_Test_Exit
End If

DoCmd.OpenQuery "qdel_Create_Quote_Import_Temp"
DoCmd.OpenQuery "qdel_Create_Quote_Import"

DoCmd.TransferText , TableName:="Import", FileName:=strCreateFileName, HasFieldNames:=True

I WANT TO ADD THE DUPLICATE LOGIC HERE BEFORE THE QUERY BELOW RUNS

DoCmd.OpenQuery "qapp_create_quote_import_Temp"
Microsoft Access

Avatar of undefined
Last Comment
crystal (strive4peace) - Microsoft MVP, Access

8/22/2022 - Mon
crystal (strive4peace) - Microsoft MVP, Access

create a duplicates query using the Query Wizard

CREATE ribbon then Query Wizard

A human will need to look at the results.
Marilyn

ASKER
I want the duplicate records to display in a pop-up window where the user can check one of the duplicates to keep.
ASKER CERTIFIED SOLUTION
crystal (strive4peace) - Microsoft MVP, Access

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes