Results 1 to 3 of 3
  1. #1
    Sandova is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Dec 2015
    Posts
    1

    Question IIF expression and #Error message

    I am a beginner level Access user. I imported an Excel spreadsheet with the my dates fields showing as text. I created a query to reformat so that they show in date format. However, when the field is blank, I get an #Error showing. How do I get it remove this message and just show a blank? Also, I am also trying to retain the field name as the column label and it will not allow. Is there a better way to make this happen?



    Table date format is text 10-19-2015. The column label I need is the field name, Start Date. If I remove the label the column returns with Expr 1 label.
    Below is my expression

    Start Date: IIf([Start Date] Is Null,"",Format(CDate([Start Date]),"mm/dd/yyyy"))

    Hopefully someone can assist me in combining two expressions to get the results I need.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Why is the field a text type?

    Advise not to use spaces or special characters/punctuation (underscore is exception) in naming convention.

    AFAIK, an alias name cannot be the same as a native field name. Why should it matter if name is different from [Start Date]? You can change labels in form or report to show whatever you want.

    CDate() function errors on Null. It is not even needed in this expression. However, it is not the cause of error in this case.

    Try:

    DateStart: Format([Start Date],"mm/dd/yyyy")

    Format() function actually returns a string value, not a true date. If you need a true date value, the Format() function will not serve. Try:

    DateStart: IIf([Start Date] Is Null, Null, CDate([Start Date]))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    I believe CDate will also return an error if a non-date string is passed to it, such as CDate("asdf").

    You may want to try:

    Code:
    IIF(IsDate([Start Date]),cdate([Start Date]),null)
    Cheers,

    Jeff

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

Similar Threads

  1. Replies: 5
    Last Post: 05-15-2015, 10:49 AM
  2. Replies: 5
    Last Post: 07-30-2014, 03:55 PM
  3. Replies: 15
    Last Post: 11-01-2013, 03:24 PM
  4. Expression is Too Complex Error Message
    By EddieN1 in forum Reports
    Replies: 1
    Last Post: 05-29-2013, 11:16 PM
  5. Replies: 2
    Last Post: 06-23-2012, 11:59 PM

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