View Full Version : Iif Date Formatting Problem


amclfc
10-14-2004, 06:20 AM
ACCESS 97

Hi, I have a text box in a report and I am trying the following within expression builder:

=IIf([Offer/Subscription End Date] Is Null,"To be advised","From " & Format([Offer/Subscription Start Date] , "long date") & " to " & Format([Offer/Subscription End Date] , "long date"))

I have also tried "dd/mmmm/yy"

I get the following error message "The function you entered can not be used in this expression."

Can I fix this expression, or is there another way I can combine the text elements of above with the date fields whilst having a long date format?

Any help very much appreciated

Uncle Gizmo
10-14-2004, 06:29 AM
first of all try this:-

=IIf(IsNull([Offer]/[Subscription End Date]),"Null","Not Null")


What answer(s) do you get?

Rich
10-14-2004, 06:30 AM
=IIf(IsNull([Offer/Subscription End Date]),"To be advised","From " & Format([Offer/Subscription Start Date] , "dd/mmmm/yy") & " to " & etc.

amclfc
10-14-2004, 06:38 AM
Rich, I got the same error message with yours

Uncle Gizmo, your =IIf(IsNull([Offer/Subscription End Date]),"Null","Not Null")came back with Not Null

perplexed very am I

This works fine (but wrong date formats): =IIf([Offer/Subscription End Date] Is Null,"To be advised","From " & [Offer/Subscription Start Date] & " to " & [Offer/Subscription End Date])

Rich
10-14-2004, 06:41 AM
Uncle Gizmo, your =IIf(IsNull([Offer/Subscription End Date]),"Null","Not Null")came back with Not Null

replace that with
=IIf(IsDate([Offer/Subscription End Date]),"Null","Valid")

amclfc
10-14-2004, 06:48 AM
This is the first time I have tried to use the format function,

I have just tried below and I still get the error message "The function you entered can not be used in this expression."?????

=Format([Offer/Subscription Start Date],"dd/mmmm/yy")

ecniv
10-14-2004, 06:52 AM
=IIf(isnull([Offer/Subscription End Date]) OR isnull([Offer/Subscription Start Date]),"To be advised","From " & Format([Offer/Subscription Start Date] , "dd mmmm yyyy") & " to " & Format([Offer/Subscription End Date] , "dd mmmm yyyy"))


otherwise it gets tricky, and you'd need to use the NZ function to check whether the date you are trying to convert but haven't checked is null... if that makes sense.


Vince

amclfc
10-14-2004, 06:59 AM
Hi Guys, you are being very helpful thank you, I still get the same error message with all our variants.

When I try =Format([Offer/Subscription Start Date],"dd/mmmm/yy") all on its own I still get the error message. So I now think my problem is to do with format if you know what I mean. Why can't I can't use format on its lonesome? (asked in a pulling my hair out styly) :-)

Rich
10-14-2004, 07:09 AM
Like I said, try the IsDate function first

ecniv
10-14-2004, 07:12 AM
try:

=iif(isnull([datefield],'',format([datefield],"dd mmmm yyyy"))

Post up your results


Vince

amclfc
10-14-2004, 07:16 AM
Hi Rich

=IIf(IsDate([Offer/Subscription End Date]),"Null","Valid") comes back with null when I have a date in the field [Offer/Subscription End Date] and comes back with valid when there is nothing in the field [Offer/Subscription End Date].

How does this help?

ecniv
10-14-2004, 07:19 AM
What Rich is trying to say is that the format function cannot work on nothing, there has to be a date there. So the isdate (you did read the help on isdate function right??) tells the comp if the data is a date.


Vince

amclfc
10-14-2004, 07:19 AM
Hi Vince

=iif(isnull([datefield],'',format([datefield],"dd mmmm yyyy"))

I get the error message "The function you entered can not be used in this expression."

Same as just having =Format([Offer/Subscription Start Date],"dd/mmmm/yy") all on its own. I defo have an isolated problem with using format on date fields

Rich
10-14-2004, 07:20 AM
because it tells me that your date field is not a valid date. Are you sure it's not a text value?

amclfc
10-14-2004, 07:21 AM
I think I get it now, will be back in a mo.......

amclfc
10-14-2004, 07:37 AM
Thank you all once again.....

I have just tried the following which should only try to format if there is a date if I have finally caught up. The fields being queried are date fields by the way with only null or dates by way of values

=IIf(IsDate([Offer/Subscription End Date]),"From " & Format([Offer/Subscription Start Date] , "dd/mmm/yy") & " to " & Format([Offer/Subscription End Date] , "dd/mmm/yy",),"To be advised")

I am still getting the same error message

I'll be back......

amclfc
10-14-2004, 08:48 AM
The problem seems to be null values as when I emulate the scenario with a table containing no null values in the date field being interigated then I have no problem, this is my latest attempt....

=Nz([Offer/Subscription End Date],"To be advised","From " & Format([Offer/Subscription Start Date] , "long date") & " to " & Format([Offer/Subscription End Date] , "long date")))

I got the usual error message :-(

Please help, I don't want to have to put some bogus date in.

Rich
10-14-2004, 12:19 PM
You need to validate the StartDate too

amclfc
10-15-2004, 04:02 AM
FIXED :D :D :D

Turned out to be a reference problem to do with a missing active X control

Thank you all very much

Lister
12-15-2004, 08:06 PM
I am now getting the same error on a 97db that I am "fixing".
What was the Active X control that was turned off or missing?

:confused:

Pat Hartman
12-16-2004, 07:23 PM
It doesn't matter what reference library is missing, Access complains about the first function that it evaluates. For most people this turns out to be Date() or Format() since those are the most used functions.