The problem is definitely not due to a syntax error with DateAdd
. This Immediate window example demonstrates your DateAdd
syntax is valid.
? DateAdd("yyyy",10,Date())
2/18/2024
And it will work the same way in VBA code or in a query.
Beware that an Access field can have both name and caption properties.
When a field has a caption assigned, that caption is used instead of the field's name in many situations. One such situation is when you open the table directly in Datasheet View.
So in your situation, the table may include a field whose caption is "OrderDate", but the actual field name is something else. And in a query, you must use the name because Access will not recognize the caption, assume it must be a parameter, and expect you to supply a value for the parameter.
Check the table design to make sure you're using the actual field name in your query.
You can avoid this problem by building your query in the Access query designer. Start it as a SELECT
query and choose from the available field names. After you have it working correctly as a SELECT
, you can convert it to the UPDATE
you actually need.
Access offers convenient hand-holding features. At times they get it your way and become annoying. But this is a case where Access' helpful tendencies can be genuinely helpful. :-)
Turns out I have a copy of Northwind from Access 2007. At least in my copy, the field is named "Order Date". So caption wasn't the culprit. Just bracket the field name so Access will recognize it as "one thing" instead of two.
UPDATE Orders
SET [Order Date] = DateAdd("yyyy",10,[Order Date]);
Notice this is another example of a problem the query designer can help you avoid.