datevalue returning #Error

G

Guest

I have a date/time field. I need to extract just the date in order to do
further date calculations. I created a calculated field using DateValue - but
if the field does not have a date, it returns #Error. So, I changed it to the
following: IIF([field] is null,"",DateValue([field])) - this leaves out the
error but now changes all the dates to text. A workaround is to have it enter
a 0 rather than leaving it blank, but then that enters the value of 12:00:00
am. Any other suggestions of how not to have the error display but prevent
the dates from changing to text?
 
A

Allen Browne

The zero-length string is the problem: that forces Access to treat the value
as text.

Instead, use Null. And wrap the expression in CVDate() to ensure it is
understood as a date:
CVDate(IIF([field] is Null, Null, DateValue([field])))

You could also use Fix() to lose the time component:
CVDate(Fix([field]))
 
G

Guest

A huge thank you!! That should do it!
--
maryj


Allen Browne said:
The zero-length string is the problem: that forces Access to treat the value
as text.

Instead, use Null. And wrap the expression in CVDate() to ensure it is
understood as a date:
CVDate(IIF([field] is Null, Null, DateValue([field])))

You could also use Fix() to lose the time component:
CVDate(Fix([field]))

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

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

maryj said:
I have a date/time field. I need to extract just the date in order to do
further date calculations. I created a calculated field using DateValue -
but
if the field does not have a date, it returns #Error. So, I changed it to
the
following: IIF([field] is null,"",DateValue([field])) - this leaves out
the
error but now changes all the dates to text. A workaround is to have it
enter
a 0 rather than leaving it blank, but then that enters the value of
12:00:00
am. Any other suggestions of how not to have the error display but prevent
the dates from changing to text?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top