Append only new records/entire record makes unique identifier

T

TommyP

Hello,
 
I have been searching the existing posts for an answer to my issue.  Many
have similar suggestions, but none of them quite fit my problem, so I
apologize if you feel this is redundant.  Here we go:
 
The ultimate goal is to append new records (and new records only) to an
existing table.  When the query runs to append records which do not already
exist in the table, I need the query to compare the entire record in the
table to the entire record in the query (as opposed to one field where an
unmatched query would be useful).  My reason for this is that it is the
entire combination of fields in each record which make the records unique.
 
For example, the records in the existing Table are:
A-B-C-D
B-C-D-E
(With each letter being a field).
 
The Query will produce record results of:
A-B-C-D
B-C-D-E
C-D-E-F
 
I only want C-D-E-F to append to the table.  I want the query to "see" that
the combination of C-D-E-F does not exist in the table, and to append it.
 
I am a fairly new user to Access, so simplified explanations would be
greatly appreciated.  Thank you so much.
 
K

KARL DEWEY

I am guessing but the following would allow you to append --
d-e-f-a
f-s-f-a
but not --
A-B-C-D
B-C-D-E

INSERT INTO TableB ( ClientID, Countycode, entrydate, [Group], [Section],
Title )
SELECT TableA.ClientID, TableA.Countycode, TableA.entrydate, TableA.Group,
TableA.Section, TableA.Title
FROM TableA LEFT JOIN TableB ON (TableA.Title = TableB.Title) AND
(TableA.Section = TableB.Section) AND (TableA.Group = TableB.Group) AND
(TableA.entrydate = TableB.entrydate) AND (TableA.Countycode =
TableB.Countycode) AND (TableA.ClientID = TableB.ClientID)
WHERE (((TableB.ClientID) Is Null) AND ((TableB.Countycode) Is Null) AND
((TableB.entrydate) Is Null) AND ((TableB.Group) Is Null) AND
((TableB.Section) Is Null) AND ((TableB.Title) Is Null));
 
T

TommyP

Thank you Karl, a component of this has worked.  It works in a Select Query
(where I did a quick run of it), and it returns those records not in the
table.  Perfect.
 
This is where I am running into an issue:  When I change it to an Append
Query, I have two sets of the same fields.  (Where the join lines exist).  I
have the fields from the Query, which actually contain the data .. and then
all of the fields from the Table, with the criteria "IS NULL".  I need to
keep the criteria in the Table fields... however, I am getting an error
message of:  "DUPLICATE OUTPUT DESTINATION" .. obviously because we have two
of every field now pulled down.  Any thoughts on how to remedy this?

Again, thank you for your time and thoughts.






KARL said:
I am guessing but the following would allow you to append --
d-e-f-a
f-s-f-a
but not --
A-B-C-D
B-C-D-E

INSERT INTO TableB ( ClientID, Countycode, entrydate, [Group], [Section],
Title )
SELECT TableA.ClientID, TableA.Countycode, TableA.entrydate, TableA.Group,
TableA.Section, TableA.Title
FROM TableA LEFT JOIN TableB ON (TableA.Title = TableB.Title) AND
(TableA.Section = TableB.Section) AND (TableA.Group = TableB.Group) AND
(TableA.entrydate = TableB.entrydate) AND (TableA.Countycode =
TableB.Countycode) AND (TableA.ClientID = TableB.ClientID)
WHERE (((TableB.ClientID) Is Null) AND ((TableB.Countycode) Is Null) AND
((TableB.entrydate) Is Null) AND ((TableB.Group) Is Null) AND
((TableB.Section) Is Null) AND ((TableB.Title) Is Null));
[quoted text clipped - 26 lines]
 
T

TommyP

I have figured out the issue in regards to my last post.  I simply deleted
the "Append To" section of the field for all of the Table Fields, which were
pulled down into the Query criteria. 

Thank you Karl, a component of this has worked.  It works in a Select Query
(where I did a quick run of it), and it returns those records not in the
table.  Perfect.
 
This is where I am running into an issue:  When I change it to an Append
Query, I have two sets of the same fields.  (Where the join lines exist).  I
have the fields from the Query, which actually contain the data .. and then
all of the fields from the Table, with the criteria "IS NULL".  I need to
keep the criteria in the Table fields... however, I am getting an error
message of:  "DUPLICATE OUTPUT DESTINATION" .. obviously because we have two
of every field now pulled down.  Any thoughts on how to remedy this?

Again, thank you for your time and thoughts.
I am guessing but the following would allow you to append --
d-e-f-a
[quoted text clipped - 20 lines]
 
K

KARL DEWEY

Open in design view and ckick the checkbox of the fields from the table that
is being appended to.

--
Build a little, test a little.


TommyP said:
Thank you Karl, a component of this has worked. It works in a Select Query
(where I did a quick run of it), and it returns those records not in the
table. Perfect.

This is where I am running into an issue: When I change it to an Append
Query, I have two sets of the same fields. (Where the join lines exist). I
have the fields from the Query, which actually contain the data .. and then
all of the fields from the Table, with the criteria "IS NULL". I need to
keep the criteria in the Table fields... however, I am getting an error
message of: "DUPLICATE OUTPUT DESTINATION" .. obviously because we have two
of every field now pulled down. Any thoughts on how to remedy this?

Again, thank you for your time and thoughts.






KARL said:
I am guessing but the following would allow you to append --
d-e-f-a
f-s-f-a
but not --
A-B-C-D
B-C-D-E

INSERT INTO TableB ( ClientID, Countycode, entrydate, [Group], [Section],
Title )
SELECT TableA.ClientID, TableA.Countycode, TableA.entrydate, TableA.Group,
TableA.Section, TableA.Title
FROM TableA LEFT JOIN TableB ON (TableA.Title = TableB.Title) AND
(TableA.Section = TableB.Section) AND (TableA.Group = TableB.Group) AND
(TableA.entrydate = TableB.entrydate) AND (TableA.Countycode =
TableB.Countycode) AND (TableA.ClientID = TableB.ClientID)
WHERE (((TableB.ClientID) Is Null) AND ((TableB.Countycode) Is Null) AND
((TableB.entrydate) Is Null) AND ((TableB.Group) Is Null) AND
((TableB.Section) Is Null) AND ((TableB.Title) Is Null));
[quoted text clipped - 26 lines]

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top