Results 1 to 4 of 4
  1. #1
    rhinodance is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    2

    Why do I get an error in a query field when error handling is built in?

    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.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Why don't you use a standard Date datatype ?? Why play with strings and numbers and attempt to make it a Date?
    There are so many things to learn and experiment with and understand ...............

    Or is this some academic exercise?

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Just check to see if the value is null before doing anything to it, i.e.
    Update_Dt: Iif(IsNull([UPDTE]),"",CDate(Mid([UPDTE],5,2) & "/" & Right([UPDTE],2) & "/" & Left([UPDTE],4)))

  4. #4
    rhinodance is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2012
    Posts
    2
    Joe: Thanks that worked. The non-date entries are actually '0' so I tested for that rather than null. I was using the ISERROR construct to cover any kind of entry into the UPDTE field that would not convert to a date though.

    Orange: If I could I would, but I don't have control over the data I'm querying. The field is from a third party an App which stores the date as a number. I then have to convert it to a date for reporting purposes.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. On Error handling
    By rivereridanus in forum Access
    Replies: 2
    Last Post: 06-18-2012, 07:46 AM
  2. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM
  3. Error Handling
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 09-14-2010, 12:17 PM
  4. Error Handling
    By trb5016 in forum Access
    Replies: 2
    Last Post: 08-10-2010, 08:37 AM
  5. #error handling
    By mws5872 in forum Access
    Replies: 4
    Last Post: 05-12-2010, 07:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums