Domanda

I'm working on the Northwind Microsoft Access database in Acceess 2007. In the Orders table there are three date fields: OrderDate, RequiredDate and ShippedDate.

All of these fields are in 1994-1996. I'm trying to input this into an ETL system, but that system does not allow dates over 15 years old.

I'd like to add 10 years to each of those three fields.

I'm trying something like this: UPDATE Orders set OrderDate = DateAdd("yyyy",10,OrderDate)

...but receive the error "Too few parameters. Expected 1." When I see that error, it's usually a typo in a column name used, but I'm not seeing it anywhere here. Any suggestions?

È stato utile?

Soluzione 2

I ended up going into Create then Query Design. In there the ribbon now showed Design as a tab. I clicked on Update and then SQL view and pasted it, then switched to design view. After saving the query, I tried to run it and it failed due to some security feature that was disabled. I enabled it and updated the database ok. This ended up doing it:

UPDATE Orders SET RequiredDate = DateAdd("yyyy",10,RequiredDate);
UPDATE Orders SET OrderDate = DateAdd("yyyy",10,OrderDate);
UPDATE Orders SET ShippedDate = DateAdd("yyyy",10,ShippedDate);

Thanks everyone for your help.

Altri suggerimenti

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.

field properties showing name and caption

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.

Instead of DATEADD("yyyy", 10, OrderDate)

Make it DATEADD(year, 10, OrderDate)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top