I'm doing a query and I have a field called UPDTE with entries that look like '20120801' in which a date in stored as a number. So '20120801' represents Aug 1, 2102. In the query I've defined a field where I'm turning this number into a date by using the CDATE function. The basic formula I'm starting with is this:
Update_Dt: CDate(Mid([UPDTE],5,2) & "/" & Right([UPDTE],2) & "/" & Left([UPDTE],4))
It works fine when UPDTE is populated. However, sometimes UPDTE is blank so trying to transform it into a date returns an error. To cover this possibility, I've expanded the formula to test for an error first and if an error is returned the result should simply be null (as represented by ""). Here's my expanded formula with error handling:
Update_Dt: IIf(IsError(CDate(Mid([UPDTE],5,2) & "/" & Right([UPDTE],2) & "/" & Left([UPDTE],4))),"",CDate(Mid([UPDTE],5,2) & "/" & Right([UPDTE],2) & "/" & Left([UPDTE],4)))
The problem is, when I run the query I get #ERROR for these blank fields instead of a null. How can my formula return #ERROR for these blanks and not null- since I'm testing for an error? Thanks.