A family of Microsoft relational database management systems designed for ease of use.
Thanks everyone, for your help.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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!
A family of Microsoft relational database management systems designed for ease of use.
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.
Thanks everyone, for your help.
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.
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.
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.
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.