Hi Damien,
What I need to do is add these records only where they
don't exist already but preserve those that do. I didn't explain
the problem well all in my op.
Actually, I understood this from your op (original post). This is why I wrote the following:
"If custno and hiercode are a combined field primary key in the sales table, you will likely
receive append query errors, if some of these combinations are already present in the table, but
you can just ignore these errors."
The Hierarchy table contains the fields....
Okay, I didn't understand that the name of one of your tables is "Hierarchy". I thought you had
three tables named: Customers, Products and Sales.
So I need to somehow test for the existence of a customer/hier
combination then if it doesn't exist, create a new record in the
sales table for that combination with zero values in the Act*, Bud*
and PotSale fields.
There should be no need to test for the existence of previous records. When you attempt to run
the update query, you should get a message that n records failed to update, where n = the number
of pre-existing records in your table. This failure will occur because a primary key must be
unique--therefore you won't be allowed to add the same record twice. You can set a default value
of zero for the Act*, Bud* and PotSale fields before running the update query. However, I see
that ActTonnes is a description, so this field is likely text, in which case you wouldn't set a
default value for that field.
My instructions are basically the same as the first time, except with amended field and table
names and setting the default values of some fields to zero before running the update query:
Create a new query. Add the Customers and Hierarchies tables. Select the CustNo and Prodhier
fields. Convert the query from a Select query into an Append query, by selecting Query > Append
Query... from the menu in query design view. Specify your Sales table as the table to append the
data to. You should see a new row in the QBE grid titled "Append To:".
Select the CustNo and ProdHhier (<---Is this spelling intentionally different?) fields. Run the
query.
If you view the SQL statement for this query, (View > SQL View from query design) you should have
something like the following:
INSERT INTO Sales ( CustNo, ProdHhier )
SELECT Customers.CustNo, Hierarchies.Prodhier
FROM Customers, Hierarchies;
Tom
_______________________________________________
Thanks for the response Tom. What I need to do is add these records only
where they don't exist already but preserve those that do. I didn't explain
the problem well all in my op.
The Customers table contains the fields custno (customer number) and a few
others, custno is the the primary key.
The Hierarchy table contains the fields prodhier and a description, prodhier
is the primary key. There are only 13 records is this table and the data is
more or less static.
The sales table contains all the sales data for all customers by product
hierarchy, so for each customer there's up to 13 product hierarchy records
with sales data for each.
I have the 3 joined with a 1 to many rel'p between customer number in the
customers table and the same field in the sale table. Same with the
hierarchies. I have referential integrity enforced in all joins with cascade
update and delete on (so if I delete a customer it gets rid of all the sale
data).
Here is how the joins are:
(hopefully you're using a fixed width font for this...)
[Customers] [Sales] [Hierarchies]
CustNo 1----> CustNo
Name ProdHhier <----1 Prodhier
Class ActTonnes Description
City ActSales
Terr ActMarg
BudTonnes
BudSales
BudMarg
PotSale
The sales table already contains data for the Act* (actual) fields
(extracted from SAP). The users will populate the Bud* (budget) fields. I
need to have all 13 hierarchies for each customer in the sales table because
the users can't create records in the form but currently only those records
where there's Act* stuff exist. So I need to somehow test for the existence
of a customer/hier combination then if it doesn't exist, create a new record
in the sales table for that combination with zero values in the Act*, Bud*
and PotSale fields.
That was the verbose description of the problem! I hope someone can assist.
I don't use Access constantly but it's ideal for this application.
cheers
Damien