Share via

Append Query creating duplicate records

Anonymous
2017-01-31T17:43:06+00:00

Hello - 

I've created an append query that works great, except for the fact that when the query is run a second time, it creates duplicate records. I would like to have the query append only the new records to the second table. 

The table that has the existing records is called "tbl_Pending_VPN_Forms" and contains the following columns: 

PendingVPNFormID (primary key)

Hub_Name

Hub_City

Hub_Zip_Code

Hub_Latitude

Hub_Longitude

Site_Description_Notes

VPN_Form_Status

HubID (data type is Number)

The table that I’m appending the records to is called "tbl_Hub_Info" and contains the following columns: 

HubID (primary key)

HubName

Hub City

Hub_Zip_Code

Hub_Latitude

Hub_Longitude

VPN_Form_Status

Site_Description_Notes

PendingVPNFormID (data type is Number) 

SQL for Append query: 

INSERT INTO

tbl_Hub_Info ( [Hub Name], [Hub City], [Hub Zip Code], [Hub Latitude], [Hub Longitude], Notes )

SELECT [tbl_Pending VPN Forms].Hub_Name, [tbl_Pending VPN Forms].Hub_City, [tbl_Pending VPN Forms].Hub_Zip_Code, [tbl_Pending VPN Forms].Hub_Latitude, [tbl_Pending VPN Forms].Hub_Longitude, [tbl_Pending VPN Forms].Site_Description_Notes

FROM [tbl_Pending VPN Forms]

WHERE ((([tbl_Pending VPN Forms].[VPN Form Status])=1));

Any suggestions as to how to fix the duplicate records from being created every time the query is run? 

Thanks in advance!

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2017-01-31T20:48:34+00:00

    Thanks everyone, for your help.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2017-01-31T18:56:10+00:00

    If you are unsure of how to include multiple column in a unique index the example below might help.

    For instance, it might be necessary to create a unique index on the EmployeeID and ProjectID columns in a ProjectEmployees table to prevent the same employee being assigned to the same project more than once.  In pre 2007 versions this is done in table design view by selecting Indexes from the View menu; in later versions by selecting Indexes on the Design ribbon.  In the dialogue which opens enter a suitable name for the index in the first empty row of the Index name column, ProjectEmployee say.  In the Field Name column of the same row enter ProjectID, and with this row still selected, in the Index Properties below, select 'Yes' as the Unique property.  Then enter EmployeeID in the Field Name column in the row immediately beneath ProjectID.  Don't enter anything in the Index name column for this row.  Close the dialogue and save the table design.

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,810 Reputation points Volunteer Moderator
    2017-01-31T18:21:54+00:00

    Hans has the better answer. You first need to define what constitutes a duplicate. Without knowing that there is no way to advise you. I would suggest Hub Name and Zipcode.

    Once you determine what constitutes a dup, it would be easier to create a unique multi-field index on the combination of the fields that make up uniqueness. This will prevent records that match that combination from being appended.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2017-01-31T18:17:02+00:00

    The question is 'what constitutes' a duplicate? 

    You need to create a Unique Index in your table containing those fields that constitutes a duplicate. 

    EDIT --

    I would not think that Site_Description_Notes would NOT be a part of that index as there might be updates to that field.  If so then you will need to compare the old to the new to see if you need to then run an Update query.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2017-01-31T18:14:59+00:00

    ciao Carol,

    hoping you got no normalization issues, try this statement :

    INSERT INTO

    tbl_Hub_Info ( [Hub Name],

                          [Hub City],

                          [Hub Zip Code],

                          [Hub Latitude],

                          [Hub Longitude], Notes )

     SELECT [tbl_Pending VPN Forms].Hub_Name,

                 [tbl_Pending VPN Forms].Hub_City,

                  [tbl_Pending VPN Forms].Hub_Zip_Code,

                  [tbl_Pending VPN Forms].Hub_Latitude,

                 [tbl_Pending VPN Forms].Hub_Longitude, [tbl_Pending VPN Forms].Site_Description_Notes

    FROM

               [tbl_Pending VPN Forms]

    WHERE

              [tbl_Pending VPN Forms].[VPN Form Status]=1

              and

            not exists (

                            select

                                    PendingVPNFormID

                             from

                                   tbl_Hub_Info where tbl_Hub_Info.pendingVPNFormID=[tbl_Pending VPN Forms].pendingVPNFormID)

    ciao, Sandro.

    Was this answer helpful?

    0 comments No comments