Hi Michel,
Thanks for replying to my post. It looks like the Update SQL you sent is
setting the value of the DateSold field. I am not trying to update the
DateSold field, but the OnInvoice field instead. To explain further what I
am trying to do: I have an InvoiceForm where with the OnClick event of a
button on the form, the Invoice is recorded and several action queries run.
One of which is called qryUpdateAdjustments. The purpose of this query is to
look at the Invoice table and see if there were any adjustments (Type = ADJ,
or CR or DB) since the last invoice to this particular customer( known as
[Store]) was sent. If there were, then those invoice adjustments need to be
applied to this invoice. (The Invoice [Type] can be either "INV" for
Invoice or "ADJ", "CR" or "DB" for different types of adjustments. Both
invoices and adjustments are recorded in the Invoices table. I should have
more aptly named this the Transactions table) The purpose of the
qryUpdateAdjustments query is to record the Invoice Number of the Invoice
that the adjustments are being applied to in the OnInvoice field of the
adjustment record . The adjustment record's Type is <> "INV" and the Store
field is the same as the one on the InvoiceForm. For this Type where [Type]
<> "INV" , DateSold is the date the Adjustment record is recorded. The date
in the adjustment record's DateSold field must be later than the DateSold of
the last invoice sent to that particular customer([Store]).
Hope I am explaining this so you can see what I am trying to do. Following
is the SQL for qryUpdateAdjustments like I originally had it. As you can
see, I had the criteria for [DateSold] > [Forms]![InvoiceForm]![DateSold]-7.
This just updated any adjustments made in the last week. However, I thought
this did not accurately reflect what could happen. Invoices are sent out on
Mondays of every week to stores that have made purchases within that week.
However, a store may not make purchases every week, in which case an
Invoice may not be generated. This same store though may have a credit or
adjustment made in that time and it would not be reflected in the next
billing so I am trying to include all adjustments made since the last time
an Invoice was sent to that [Store].
PARAMETERS [Forms]![InvoiceForm]![StoreCode] Text ( 255 ),
[Forms]![InvoiceForm]![DateSold] DateTime;
UPDATE Invoices SET Invoices.OnInvoice =
[Forms]![InvoiceForm]![txtInvoiceNumber]
WHERE (((Invoices.Type)<>"INV") AND
((Invoices.Store)=[Forms]![InvoiceForm]![StoreCode]) AND
((Invoices.DateSold)>[Forms]![InvoiceForm]![DateSold]-7));
I so appreciated your help with this.
Joan
Michel Walsh said:
Hi,
UPDATE Invoices SET DateSold=DMax("DateSold", "Invoices",
"Store=FORMS!InvoiceForm!StoreCode")
and execute it with
DoCmd.RunSQL "..."
If you use
CurrentDb.Execute "...", then the FORMS!InvoiceForm!StoreCode won't be
solved automatically for you (while it is with DoCmd) and you would be
prompted for it.
Note that is it possible that the third argument of DMax may involve
something like AND Type='inv', the complete criteria was not clear from
the original message, but I did not include it to not overload the syntax,
which would have obscure the basic idea.
Hoping it may help,
Vanderghast, Access MVP
Joan said:
Hi,
I am trying to build an update query whereby I set the value of field
[OnInvoice] to the value in Forms!InvoiceForm!txtInvoiceNumber where (the
criteria) [DateSold] is greater than the result of another query. The SQL
of the other query is:
SELECT Max(Invoices.DateSold) AS MaxOfDateSold
FROM Invoices
GROUP BY Invoices.Type, Invoices.Store, Invoices.[Invoice Number]
HAVING (((Invoices.Type)="INV") AND
((Invoices.Store)=[Forms]![InvoiceForm]![StoreCode]));
How do I write the update query so that the [DateSold] field in this query
is greater than MaxOfDateSold. What do I put on the criteria line? I tried
putting : >qryUpdPreAdjustments.[MaxOfDateSold] but then I get a message
asking for the value of Forms!InvoiceForm!DateSold. This expression is not
in either query.
Thanks ahead for any help with this.
Joan