J
Joan
Can anyone tell me how to update a field using an update query where the
Update To value is a field in another table and there is limiting criteria
on the Update To value? I will try to explain what I am needing. I want to
update a field for certain records in the dogs table where the Returned
field (from Dogs) Is Not Null. I want to update Dogs.Store1 to a value from
Invoices.Store. However, a single dog could have more than 1 invoice record
if it is sold, returned and then resold. For these returned dogs, I want
the Invoice.Store value from Invoices where the Invoice Number is the
minimum for that dog. In other words, the first store that the dog was sold
to. Invoice Numbers are in chronological consecutive order.
The problem enters because Dogs is not directly linked to Invoices, but is
to Sales and Sales is directly linked to Invoices. How do I tell my query
how to find the correct Invoices.Store value to use as an Update To value?
I've tried using the following expression as the Update To value, but it
did not work.
DLookUp("[Store]","Invoices"," DMin([Sales].[Invoice Number], Sales, [Dog
Number]= & [Dog Number])")
The SQL I tried:
UPDATE Dogs SET Dogs.Store1 = DLookUp("[Store]","Invoices","
DMin([Sales].[Invoice Number], Sales, [Dog Number]= & [Dog Number])")
WHERE (((Dogs.Returned) Is Not Null));
Relationship is:
INVOICES < SALES > DOGS
An INVOICE can have many dogs per invoice
A single DOG can be sold many times and therefore have more than one
invoice. As in sold, returned and resold.
Tables & Primary Keys:
INVOICES
Invoice Number (PK)
SALES
Invoice Number (PK)
Dog Number (PK)
DOGS
Dog Number (PK)
Any assistance in getting this update to work would be so appreciated!
Joan
Update To value is a field in another table and there is limiting criteria
on the Update To value? I will try to explain what I am needing. I want to
update a field for certain records in the dogs table where the Returned
field (from Dogs) Is Not Null. I want to update Dogs.Store1 to a value from
Invoices.Store. However, a single dog could have more than 1 invoice record
if it is sold, returned and then resold. For these returned dogs, I want
the Invoice.Store value from Invoices where the Invoice Number is the
minimum for that dog. In other words, the first store that the dog was sold
to. Invoice Numbers are in chronological consecutive order.
The problem enters because Dogs is not directly linked to Invoices, but is
to Sales and Sales is directly linked to Invoices. How do I tell my query
how to find the correct Invoices.Store value to use as an Update To value?
I've tried using the following expression as the Update To value, but it
did not work.
DLookUp("[Store]","Invoices"," DMin([Sales].[Invoice Number], Sales, [Dog
Number]= & [Dog Number])")
The SQL I tried:
UPDATE Dogs SET Dogs.Store1 = DLookUp("[Store]","Invoices","
DMin([Sales].[Invoice Number], Sales, [Dog Number]= & [Dog Number])")
WHERE (((Dogs.Returned) Is Not Null));
Relationship is:
INVOICES < SALES > DOGS
An INVOICE can have many dogs per invoice
A single DOG can be sold many times and therefore have more than one
invoice. As in sold, returned and resold.
Tables & Primary Keys:
INVOICES
Invoice Number (PK)
SALES
Invoice Number (PK)
Dog Number (PK)
DOGS
Dog Number (PK)
Any assistance in getting this update to work would be so appreciated!
Joan