Syntax error DateDiff

  • Thread starter Thread starter Søren
  • Start date Start date
S

Søren

I write the following in the Control Source property of a form text box, but
get a message that the syntax is wrong:

=DateDiff("d", date, [SidsteOfStatusændringDato])

What am I doing wrong?
 
Try:
=DateDiff("d", Date(), [SidsteOfStatusændringDato])

Date works in VBA code, but it's best to include the function brackets in
other contexts.
 
Thanks a lot but actually, I still get the same syntax error message. I am
really frustrated about this.

Best,
Søren


Allen Browne said:
Try:
=DateDiff("d", Date(), [SidsteOfStatusændringDato])

Date works in VBA code, but it's best to include the function brackets in
other contexts.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Søren said:
I write the following in the Control Source property of a form text box,
but
get a message that the syntax is wrong:

=DateDiff("d", date, [SidsteOfStatusændringDato])

What am I doing wrong?
 
Okay, other possibilities:

1. Look at the Name property of this text box. Make sure it's not the same
as the name of any fields in the form. For example, it cannot be named
SidsteOfStatusændringDato.

2. What isSidsteOfStatusændringDato?
Is it:
a) A field from a table?
If so, what data type is this field when you open the table in design view?

b) A calculated field in a query?
If so, what is the expression, and the data type of the fields in that
expression?

c) A text box with an expression in its Control Source?
If so, what is the expression, and the data type of the fields in that
expression? And what is in the Format property of the text box?

3. Are there any other calculated controls on this form? Do they work?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Søren said:
Thanks a lot but actually, I still get the same syntax error message. I am
really frustrated about this.

Best,
Søren


Allen Browne said:
Try:
=DateDiff("d", Date(), [SidsteOfStatusændringDato])

Date works in VBA code, but it's best to include the function brackets in
other contexts.

Søren said:
I write the following in the Control Source property of a form text box,
but
get a message that the syntax is wrong:

=DateDiff("d", date, [SidsteOfStatusændringDato])
 
Thanks for getting back to me.

Ad. 1: The name of the text box is unique.

Ad. 2: SidsteOfStatusændringDato is a date taken from a query that selects
the last of a number of dates related to a particular record.

Ad. 3: There are no other calculated controls in the form.

Best,
Søren



Allen Browne said:
Okay, other possibilities:

1. Look at the Name property of this text box. Make sure it's not the same
as the name of any fields in the form. For example, it cannot be named
SidsteOfStatusændringDato.

2. What isSidsteOfStatusændringDato?
Is it:
a) A field from a table?
If so, what data type is this field when you open the table in design view?

b) A calculated field in a query?
If so, what is the expression, and the data type of the fields in that
expression?

c) A text box with an expression in its Control Source?
If so, what is the expression, and the data type of the fields in that
expression? And what is in the Format property of the text box?

3. Are there any other calculated controls on this form? Do they work?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Søren said:
Thanks a lot but actually, I still get the same syntax error message. I am
really frustrated about this.

Best,
Søren


Allen Browne said:
Try:
=DateDiff("d", Date(), [SidsteOfStatusændringDato])

Date works in VBA code, but it's best to include the function brackets in
other contexts.

I write the following in the Control Source property of a form text box,
but
get a message that the syntax is wrong:

=DateDiff("d", date, [SidsteOfStatusændringDato])
 
Okay, let's break this down.

With the form open, open the Immediate Window (Ctrl+G) and enter:
? Forms.[Form1]!SidsteOfStatusændringDato
substituting your form name for form1.
Does it respond with the correct result when you press Enter?

If so, try:
? TypeName(Forms.[Form1]!SidsteOfStatusændringDato.Value))
Does it indicate that it understands the value as a date?

If so, try:
? DateDiff("d", Date(), Forms.[Form1]!SidsteOfStatusændringDato)
Does it give the correct number of days?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Søren said:
Thanks for getting back to me.

Ad. 1: The name of the text box is unique.

Ad. 2: SidsteOfStatusændringDato is a date taken from a query that selects
the last of a number of dates related to a particular record.

Ad. 3: There are no other calculated controls in the form.

Best,
Søren



Allen Browne said:
Okay, other possibilities:

1. Look at the Name property of this text box. Make sure it's not the
same
as the name of any fields in the form. For example, it cannot be named
SidsteOfStatusændringDato.

2. What isSidsteOfStatusændringDato?
Is it:
a) A field from a table?
If so, what data type is this field when you open the table in design
view?

b) A calculated field in a query?
If so, what is the expression, and the data type of the fields in that
expression?

c) A text box with an expression in its Control Source?
If so, what is the expression, and the data type of the fields in that
expression? And what is in the Format property of the text box?

3. Are there any other calculated controls on this form? Do they work?

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Søren said:
Thanks a lot but actually, I still get the same syntax error message. I
am
really frustrated about this.

Best,
Søren


:

Try:
=DateDiff("d", Date(), [SidsteOfStatusændringDato])

Date works in VBA code, but it's best to include the function brackets
in
other contexts.

I write the following in the Control Source property of a form text
box,
but
get a message that the syntax is wrong:

=DateDiff("d", date, [SidsteOfStatusændringDato])
 
In addition to all of the good advice Allen has given you, what's your list
separator character set to through Regional Settings? (I can't remember how
to determine this off the top of my head in other operating systems, but in
XP, you'd select Regional and Language Options from the Control Panel, click
on the Customize button on the Regional Options tab and look on the Numbers
tab.) If it's something other than comma (semi-colon is common), use that as
the separator in your function call:

=DateDiff("d"; Date(); [SidsteOfStatusændringDato])

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Søren said:
Thanks a lot but actually, I still get the same syntax error message. I am
really frustrated about this.

Best,
Søren


Allen Browne said:
Try:
=DateDiff("d", Date(), [SidsteOfStatusændringDato])

Date works in VBA code, but it's best to include the function brackets in
other contexts.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Søren said:
I write the following in the Control Source property of a form text box,
but
get a message that the syntax is wrong:

=DateDiff("d", date, [SidsteOfStatusændringDato])

What am I doing wrong?
 
Thanks for all this.

Allen, right now Access will not even allow me to enter the sentence into
the control source property, it immediately displays a syntax error message.
So I was not able to go through the steps you kindly suggested.

I will check the list separator settings.

Best,
Søren


Douglas J. Steele said:
In addition to all of the good advice Allen has given you, what's your list
separator character set to through Regional Settings? (I can't remember how
to determine this off the top of my head in other operating systems, but in
XP, you'd select Regional and Language Options from the Control Panel, click
on the Customize button on the Regional Options tab and look on the Numbers
tab.) If it's something other than comma (semi-colon is common), use that as
the separator in your function call:

=DateDiff("d"; Date(); [SidsteOfStatusændringDato])

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Søren said:
Thanks a lot but actually, I still get the same syntax error message. I am
really frustrated about this.

Best,
Søren


Allen Browne said:
Try:
=DateDiff("d", Date(), [SidsteOfStatusændringDato])

Date works in VBA code, but it's best to include the function brackets in
other contexts.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

I write the following in the Control Source property of a form text box,
but
get a message that the syntax is wrong:

=DateDiff("d", date, [SidsteOfStatusændringDato])

What am I doing wrong?
 
Douglas,

You were right, my list separator setting was set to ";", and the moment I
started using the semi-colon in stead of the comma everything worked.

Thanks everybody for alle your help!

Best,
Søren


Douglas J. Steele said:
In addition to all of the good advice Allen has given you, what's your list
separator character set to through Regional Settings? (I can't remember how
to determine this off the top of my head in other operating systems, but in
XP, you'd select Regional and Language Options from the Control Panel, click
on the Customize button on the Regional Options tab and look on the Numbers
tab.) If it's something other than comma (semi-colon is common), use that as
the separator in your function call:

=DateDiff("d"; Date(); [SidsteOfStatusændringDato])

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Søren said:
Thanks a lot but actually, I still get the same syntax error message. I am
really frustrated about this.

Best,
Søren


Allen Browne said:
Try:
=DateDiff("d", Date(), [SidsteOfStatusændringDato])

Date works in VBA code, but it's best to include the function brackets in
other contexts.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

I write the following in the Control Source property of a form text box,
but
get a message that the syntax is wrong:

=DateDiff("d", date, [SidsteOfStatusændringDato])

What am I doing wrong?
 
Excellent "hit" Douglas!
I would never have thought of that. Thanks for helping with this one...

Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."

Douglas J. Steele said:
In addition to all of the good advice Allen has given you, what's your
list separator character set to through Regional Settings? (I can't
remember how to determine this off the top of my head in other operating
systems, but in XP, you'd select Regional and Language Options from the
Control Panel, click on the Customize button on the Regional Options tab
and look on the Numbers tab.) If it's something other than comma
(semi-colon is common), use that as the separator in your function call:

=DateDiff("d"; Date(); [SidsteOfStatusændringDato])

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Søren said:
Thanks a lot but actually, I still get the same syntax error message. I
am
really frustrated about this.

Best,
Søren


Allen Browne said:
Try:
=DateDiff("d", Date(), [SidsteOfStatusændringDato])

Date works in VBA code, but it's best to include the function brackets
in
other contexts.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

I write the following in the Control Source property of a form text
box,
but
get a message that the syntax is wrong:

=DateDiff("d", date, [SidsteOfStatusændringDato])

What am I doing wrong?
 
Back
Top