Calculated field in query

JohnPapa

Registered User.
Local time
Tomorrow, 01:10
Joined
Aug 15, 2010
Messages
1,088
I get the error message which appears in the attachment when I try to create a Calculated field using the DateAdd function.

Any ideas?
 

Attachments

  • CalculatedField.jpg
    CalculatedField.jpg
    103.4 KB · Views: 25
Do all those fields have values?
If I enter that function
Access CamelCases the function name?
It also surrounds the field names with [ & ]
 
Last edited:
Syntax looks right.
I cannot replicate issue.
Null in Number argument triggers a "data type mismatch" error, null in Date argument returns Null.

Will DateAdd work in the VBA Immediate Window?
 
Do all those fields have values?
If I enter that function
Access CamelCases the function name?
It also surrounds the field names with [ & ]
Yes the fields have values.
What is CamelCase?
Not clear what you mean with [&]
 
Camel case is capitalizing first letter of each word - so you get "humps" in middle of text string.
Gasman means left and right bracket characters - "[" and "]"
 
Compare what was entered to what was generated as shown in the code segment.
1744992227936.png


Code:
SELECT tblDaily.DailyDate, tblDaily.Factor, DateAdd("m",[factor],[dailydate]) AS Expr1
FROM tblDaily;
 
When I run the query without the Calculated field I get what appears in the attachment.
 

Attachments

  • CalculatedField2.jpg
    CalculatedField2.jpg
    25 KB · Views: 18
That does not show the dtmCreation field.

If you want to provide db for analysis, follow instructions at bottom of my post.
 
That was my post Duane.
I was just trying to replicate the issue.
 
That was my post Duane.
I was just trying to replicate the issue.
I realize this was your version and expect the OP would understand (and possibly post text SQL versus an image). I wanted something to simply copy and paste.
 
Based on your location, should you use ";" in place of ","?

DateAdd("m";[factor];[dailydate]) AS Expr1
It appears that the following works.

Expr1: DateAdd("m";[lngMHMonth];[tblMedicalHistoryListNew].[dtmCreation])

Where in the documentation does it say to use ";" instead of "," ?
 
It might not. It all depends on your system seperator.

Very surprised you have not discovered this before. :(
Your dates appear in UK format, where are you based? In the UK here we use the comma. In Europe, some countries use the semi-colon, but you cannot chop and change AFAIK.
 
Trivial response (dinner on the stove)... you might need to surround your date value with "#" or cast it to date with CDATE() ?
 
It might not. It all depends on your system seperator.

Very surprised you have not discovered this before. :(
Your dates appear in UK format, where are you based? In the UK here we use the comma. In Europe, some countries use the semi-colon, but you cannot chop and change AFAIK.
Yes, I am very surprised as well.
The culprit is the List Separator, which was set to ";". When I set it to ".", the original expression worked.
 

Users who are viewing this thread

Back
Top Bottom