fredg said:
Table: tblInvoiceLine
Field: invlineStatus
Goal: Change the field from "P" to a "C" after printing of the invoice
during the report's 'Close Event'.
Tim
Let me see if I understand your set up now.
You have a field named [invlineStatus].
It is a Text datatype field, not a check box field
as I originally thought. Among it's possible values
are a "P" or a "C".
CurrentDb.Execute "Update tblInvoiceLine Set
tblInvoiceLine.[invlineStatus] ='C'
Where tblInvoiceLine.[invlineStatus] = 'P';", dbFailOnError
The above shold be all on one line, unless you know how to break the
line.
I assume the query (and the report) will show all of the 'P' records.
If the query only shows some of the 'P' records, then you need to
further restrict the Update using whatever other criteria was used by
the query to restrict the data.
Fred,
Yes, you have an understanding of what I am trying to accomplish.
I will use your code and do test runs to verify it all works correctly, but
it sure looks what I need. And I do appreciate you making note about the
Restricting The Update. It is true that this query used to pull out these
lines to print, does have another criteria used besides the status flag.
Had I used your code, I suppose all invoices that were 'P'ending would have
been changed to 'C'losed. Now that wouldn't have been good.
I have one other criteria and that is BoatID = 8 so that only items used on
this boat will print out in the report and only those items that are
pending. I will update your statement to this;
CurrentDb.Execute "Update tblInvoiceLine Set
tblInvoiceLine.[invlineStatus] ='C'
Where tblInvoiceLine.[invlineStatus] = 'P';", dbFailOnError
CurrentDb.Execute "Update tblInvoiceLine Set
tblInvoiceLine.[invlineStatus]='C' Where "AND I NEED HELP HERE"
I understand the part about tblInvoiceLine.[invlineStatus]='P', but I want
to insert before the other criteria used in the Query.
Here is the SQL statement's view of what the criteria is I am using;
SELECT tblInvoice.invBoatId, tblInvoiceLine.invlineStatus,
tblInvoiceLine.invlineInvId, tblInvoiceLine.invlineId,
tblInvoiceLine.invlineQty, tblItem.itemDescription,
tblInvoiceLine.invlinePrice
FROM tblItem INNER JOIN (tblInvoice INNER JOIN tblInvoiceLine ON
tblInvoice.invId = tblInvoiceLine.invlineInvId) ON tblItem.itemId =
tblInvoiceLine.invlineItemId
WHERE (((tblInvoice.invBoatId) Like "8") AND ((tblInvoiceLine.invlineStatus)
Like "O"))
ORDER BY tblInvoice.invBoatId, tblInvoiceLine.invlineStatus,
tblInvoiceLine.invlineInvId, tblInvoiceLine.invlineId;
I need to make sure the only records changed are related to Boat #8 which is
tblInvoice.invBoatId. How do I reference this when it is not in the same
table as the invoice line items?
Maybe you can tell, this is my first real report I am tackling.
Thank you for the help on this.
Tim
According to your SQL Where clause [BoatID] is text datatype (You
placed it within Quotes "8").
CurrentDb.Execute "Update tblInvoiceLine Set
tblInvoiceLine.[invlineStatus] ='C'
Where tblInvoiceLine.[invlineStatus] = 'P'
AND [BoatID] = '8';" , dbFailOnError
If , however, [BoatID] is a Number datatype, then use:
...... AND [BoatID] = 8;" , dbFailOnError
*********
NOTE: Your SQL Where clause above needs a bit of help.
Select .... WHERE (((tblInvoice.invBoatId) Like "8") AND
((tblInvoiceLine.invlineStatus) Like "O"))
In your Where clause use the = sign:
WHERE (((tblInvoice.invBoatId) = "8") AND
((tblInvoiceLine.invlineStatus) = "O"))
The LIKE keyword is used when you are using the wild card * and are
only inputting part of the text, i.e.
Where [BoatID] LIKE "8*" and [invlineStatus] LIKE "O*"
(assuming both [BoatID] and [invlineStatus] are Text datatypes.)
This would return all records if [BoatID] starts with the number 8
(8456, 812, 80, etc.) and the [invlineStatus] starts with the letter
O (Oregon, Ohio, etc. ).
Also, the above is hard coded into the query.
You cannot get a different BoatID or invlineStatus without changing
the query criteria. Is that what you want?
An alternative would be to use a query parameter prompt, so that the
user could use the same query to get different records, without
changing the query.
WHERE (((tblInvoice.invBoatId) = [Enter the BoatID] ) AND
((tblInvoiceLine.invlineStatus) = [Enter invlineStatus]))
You'll get prompted for both parameters.
If you use the above parameter you need to alter the Execute code in
the Report close event, as you are no longer hard coding the "8"
BoatID.
Add an unbound text control to the report header.
Set it's control source to
= [Enter the Boat ID]
(Make sure this is spelled exactly the same as in the query.)
Name this control "TextParameter".
You can make this control not visible (or make the entire Header not
visible, as you wish).
Then change the CurrentDb.Execute Update to:
CurrentDb.Execute "Update tblInvoiceLine Set
tblInvoiceLine.[invlineStatus] ='C'
Where tblInvoiceLine.[invlineStatus] = 'P'
AND [BoatID] = '" & [TextParameter] & "';" , dbFailOnError
Make sure the parameter Enter BoatID is spelled exactly the same in
the query and in the report header.
Again, the above assumes [BoatID] is a Text datatype.
If [BoatID] is Number datatype, do not use the quotes around the 8 in
the hard coded code, and change the last part of the code using the
parameter to:
.... AND [BoatID] = " & [TextParameter] & ";" , dbFailOnError
Confused yet?