Currently:
UPDATE TrackingTable
SET January =
(SELECT COUNT(*) AS Total
FROM MigTable
WHERE CostSplit = 'Churn'
AND Format(ActionDt,'mmmm') = 'January'
AND Format(ActionDt,'yyyy') = '2008')
WHERE Initiative = 'MigInit'
Can you do this instead:
SELECT COUNT(*) AS Total
FROM MigTable
WHERE CostSplit = 'Churn'
AND Format(ActionDt,'mmmm') = 'January'
AND Format(ActionDt,'yyyy') = '2008'
Then refer to the results of this query for the second one:
UPDATE TrackingTable
SET January = (Total value here)
WHERE Initiative = 'MigInit'
You have several methods to do this, including creating the first query with a reference to controls on the form so they can take parameters directly from the form, and then creating an update query that references the first query. You can also do all of this with code.
Two things: Total is a reserved word, so not a good name for a field alias. Also, is '2008' a string or integer?
Another issue is that it is problematic doing value transactions in the middle of an executing SQL string in Access. Is there another way to get this data before you build the string:
Format(ActionDt,'mmmm')
Format(ActionDt,'yyyy')
Did any of that help?
mmcdonal
Look it up at:
http://wrox.books24x7.com