DatePart query with Date() was working, no longer works (1 Viewer)

dalcazar

New member
Local time
Today, 01:02
Joined
Jul 7, 2021
Messages
6
Hi all, I had a query that was working but has since broken due to one of the tables being moved, now I can't get the DatePart function to work.

I'm trying to get the year from today's date by using the expression Year: DatePart("yyyy",Date())

This was working before, (although for some reason the saved version says Year: DatePart("yyyy"IDate()) <---- note the pipe | character in there.

Now, I can't get it to work at all. It just says "The expression you entered contains invalid syntax. You omitted an operand or operator, you entered and invalid character co comma, or you entered text without surrounding it in quotation marks.

As far as I can research, the syntax is correct, it just refuses to work. Any ideas on the cause/fix for this?
 

June7

AWF VIP
Local time
Today, 00:02
Joined
Mar 9, 2014
Messages
5,472
Table moved where? That should not affect this expression. Why is pipe character in expression instead of comma? Can you change it?

Could use Year(Date())

Year is a reserved word. Advise not to use reserved words as names. I would use Yr for alias name.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:02
Joined
May 7, 2009
Messages
19,243
change the Pipe character to comma again.
your query got corrupted.
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:02
Joined
Sep 21, 2011
Messages
14,301
I would just use Year() and be done with it. :)
 

Josef P.

Well-known member
Local time
Today, 10:02
Joined
Feb 2, 2023
Messages
826
There is probably | set as list separator in Windows.

So I can at least reproduce an error.

1. Set list separator
ListSeparator.png


2. insert SQL in Query (SQL View)
Code:
SELECT TestTab.ID, DatePart("yyyy",Date()) as Y
FROM TestTab;

3. Change to Design view
design-view.png


4. Execute query => Error
error.png

When you try to switch to the SQL view, the same error message appears.
The error message shown in #1 appears when you try to change the entry in the query editor.
 
Last edited:

Mike Krailo

Well-known member
Local time
Today, 04:02
Joined
Mar 28, 2020
Messages
1,044
If that is the case, then the next question is why in the heck would anyone change the list separator like that? Is that a per user thing or global for the whole computer?
 

Josef P.

Well-known member
Local time
Today, 10:02
Joined
Feb 2, 2023
Messages
826
Or you ask the question like this: Why does Access use the Windows settings when it seems to work only with the Windows default settings?
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:02
Joined
Sep 21, 2011
Messages
14,301
Using a reserved word as well ? :(
 

Josef P.

Well-known member
Local time
Today, 10:02
Joined
Feb 2, 2023
Messages
826
The error is not caused by a reserved word. In my example in #5, no reserved word is used.
 

Gasman

Enthusiastic Amateur
Local time
Today, 09:02
Joined
Sep 21, 2011
Messages
14,301
The error is not caused by a reserved word. In my example in #5, no reserved word is used.
Not saying it was, just that a reserved word was being used.
 

dalcazar

New member
Local time
Today, 01:02
Joined
Jul 7, 2021
Messages
6
There is probably | set as list separator in Windows.

So I can at least reproduce an error.

1. Set list separator
View attachment 109210

2. insert SQL in Query (SQL View)
Code:
SELECT TestTab.ID, DatePart("yyyy",Date()) as Y
FROM TestTab;

3. Change to Design view
View attachment 109211

4. Execute query => Error
View attachment 109213
When you try to switch to the SQL view, the same error message appears.
The error message shown in #1 appears when you try to change the entry in the query editor.
Well called good sir, this was indeed the issue. Access was replacing the list separator automatically.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:02
Joined
May 7, 2009
Messages
19,243
if it is constantly changing the comma to a pipe, probably a Regional setting problem?
 

Users who are viewing this thread

Top Bottom