dbTalk Databases Forums  

IIF Statement, Date String #Error

comp.databases.ms-access comp.databases.ms-access


Discuss IIF Statement, Date String #Error in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chris
 
Posts: n/a

Default IIF Statement, Date String #Error - 07-27-2012 , 12:00 PM






Hi all,
I'm am trying to create a custom date string where a date exists for my field: [LastDistrictImportDate]. My date format alone works fine, but when I put it in the IIF statement, I get an #Error.

Where no date exists, the IIF statement is evaluating fine (to ""). Even if there's a better way to do this, I'd like to know what's wrong with what I've got...

Doesn't Work (where date exists):
Last Import Date: IIf([LastDistrictImportDate]>"",(Right("0" & Month([LastDistrictImportDate]),2) & "/" & Day([LastDistrictImportDate]) & "/" & Year([LastDistrictImportDate])),"")

Just the custom date part works fine:
aFormattedDate: Right("0" & Month([LastDistrictImportDate]),2) & "/" & Day([LastDistrictImportDate]) & "/" & Year([LastDistrictImportDate])

Reply With Quote
  #2  
Old   
Chris
 
Posts: n/a

Default Re: IIF Statement, Date String #Error - 07-27-2012 , 03:29 PM






On Friday, July 27, 2012 1:00:50 PM UTC-4, Chris wrote:
Quote:
Hi all, I'm am trying to create a custom date string where a date exists for my field: [LastDistrictImportDate]. My date format alone works fine, but when I put it in the IIF statement, I get an #Error. Where no date exists, the IIF statement is evaluating fine (to ""). Even if there's a better way to do this, I'd like to know what's wrong with what I've got... Doesn't Work (where date exists): Last Import Date: IIf([LastDistrictImportDate]>"",(Right("0" & Month([LastDistrictImportDate]),2) & "/" & Day([LastDistrictImportDate]) & "/" & Year([LastDistrictImportDate])),"") Just the custom datepart works fine: aFormattedDate: Right("0" & Month([LastDistrictImportDate]),2) & "/" & Day([LastDistrictImportDate]) & "/" & Year([LastDistrictImportDate])
OK, figured out my own fix. Changed if clause to: nz([LastDistrictImportDate],"") <> "". Not sure why it's a fix, probably has to do with data type.

Reply With Quote
  #3  
Old   
Ron Paii
 
Posts: n/a

Default Re: IIF Statement, Date String #Error - 07-29-2012 , 07:31 PM



"Chris" <chris_hollstein (AT) hotmail (DOT) com> wrote

Quote:
On Friday, July 27, 2012 1:00:50 PM UTC-4, Chris wrote:
Hi all, I'm am trying to create a custom date string where a date exists
for my field: [LastDistrictImportDate]. My date format alone works fine,
but when I put it in the IIF statement, I get an #Error. Where no date
exists, the IIF statement is evaluating fine (to ""). Even if there's a
better way to do this, I'd like to know what's wrong with what I've
got... Doesn't Work (where date exists): Last Import Date:
IIf([LastDistrictImportDate]>"",(Right("0" &
Month([LastDistrictImportDate]),2) & "/" & Day([LastDistrictImportDate])
& "/" & Year([LastDistrictImportDate])),"") Just the custom date part
works fine: aFormattedDate: Right("0" &
Month([LastDistrictImportDate]),2) & "/" & Day([LastDistrictImportDate])
& "/" & Year([LastDistrictImportDate])

OK, figured out my own fix. Changed if clause to:
nz([LastDistrictImportDate],"") <> "". Not sure why it's a fix, probably
has to do with data type.
It works because Null cannot be compared to anything by having NZ convert
the missing date to an empty string, you can compare it with another empty
string. A better way may be iif(not isdate([LastDistrictImportDate]), ....

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.