John,
That code works great and does just what I want
EXCEPT
Can I avoid the Popup warning (You are about to update 1 record)??
Now your question is worth answering because I may be going about this the
hard way (if it works it is right - right??) - However I can't seem to
explain myself so that my need is clear.
Let me try again.
"tblCustomers"
has all my customer info plus a field for "LastOrderDate" (Meaning the Last
time they placed an order)
"refLastOrderDate"
is a single row table where the admin can limit how long a customer list is
getting by entering a date that he wishes to have no customers listed who
have not ordered since that time
my query to open the form "frmCustomerList " filters great based upon the
above 2 objects
HOWEVER there is currently no way to enter the "LastOrderDate" in
"tblCustomers"
"tblOrders" has a field called "OrderDate" which when an order form
("frmOrders")opens is populated with todays date.
When I close (Go to Print Preview) "frmOrders" I want that OrderDate (Todays
date)
to populate the field "LastOrderDate" in "tblCustomers" FOR THAT CUSTOMER
so that the filter will work.
SO I just put the code you gave me in the print button ON Click event code.
Which now looks like this:
--------------------------------------------------------------
Private Sub cmdPrint_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String
stDocName = "Order Invoice"
DoCmd.OpenReport stDocName, acPreview
DoCmd.RunSQL "UPDATE [tblCustomers] SET [LastOrderDate]=#" &
Me.OrderDate & "# WHERE CustomerID = " & Me.CustomerID
'DoCmd.Close acForm, "frmOrders", acSaveYes
End Sub
----------------------------------------------------------------------------
It works and does what I want. (Except for the warning) so I am happy
But if there is an easier way......I am all ears
Thanks much,
Dave
John Spencer said:
DoCmd.RunSQl "UPDATE [tblCustomers] SET [LastOrderDate]=#" & Me.OrderDate
& "# WHERE CustomerID = """ & me.CustomerID & """"
OR if customerId is a number field
DoCmd.RunSQl "UPDATE [tblCustomers] SET [LastOrderDate]=#" & Me.OrderDate
& "# WHERE CustomerID = " & me.CustomerID
Of course, the question might be, why are you doing this. You should
always be able to get the LastOrderDate for any customer with an aggregate
query.
SELECT CustomerID, Max(OrderDate)
FROM Orders
GROUP BY CustomerID
That should always give you the latest date. If you use your statement,
you have to remember to update the LastOrderDate every time and also you
need to avoid changing the date if the current LastOrderDate is after the
date you would be updating to.
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
DoCmd.RunSQl "UPDATE [tblCustomers] SET [LastOrderDate]=#" & Me.OrderDate
& "#"
How can I alter this query to include critera to only update a single
record?
I have this avaiable on the form this code is behind:
me.CustomerID
Any way to include that criteria in the above query?
Thanks
D