Results 1 to 7 of 7
  1. #1
    nggman is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    27

    Combine 2 functions for one field in Query Design View


    Is there a way to combine 2 different functions for the same field (column) in Query Design View? (Access 2016) For example, I have this for my discharge date :
    Discharge Date: DateValue([RAH_ATD_TO_DT]). I want to add a second function to this same statement. I want to add the Nz function so I do not get #Error if the field is blank. I can accomplish this in 2 separate fields (columns) but I want to do it in 1. Thank you.

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    This shouldn’t cause any problems. What have you attempted so far?

    Nz(datevalue([rah_atd_to_dt],whatever you want your null value to be)

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Andy, DateValue will error if the field is Null or empty string or any string that can't be converted to a date.


    What do you want to show if the field is Null?

    Why do you need DateValue? Why isn't the value already a date?

    DateValue(Nz([RAH_ATD_TO_DT], "1/1/1900"))

    or

    DateValue(Nz([RAH_ATD_TO_DT], 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.

  4. #4
    nggman is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    27
    No, the field contains the time also. That is why I am using DateValue. I want the field to be blank if there is no date.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Then:

    IIf([RAH_ATD_TO_DT] Is Null, Null, DateValue([RAH_ATD_TO_DT]))
    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.

  6. #6
    nggman is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Oct 2017
    Posts
    27
    Worked great!! Thank you!!

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Keep in mind IIf() in SQL is different from IIf() in Access and VBA. The expression would still error in Access or VBA because all parts must be able to be evaluated, otherwise the entire expression will return error.

    So in Access and VBA would have to:

    IIf(IsNull([RAH_ATD_TO_DT]), Null, DateValue(Nz([RAH_ATD_TO_DT], 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.

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

Similar Threads

  1. Replies: 2
    Last Post: 07-13-2017, 10:44 AM
  2. Replies: 3
    Last Post: 04-18-2017, 02:28 AM
  3. Replies: 3
    Last Post: 07-10-2015, 08:28 AM
  4. Replies: 1
    Last Post: 02-16-2013, 09:05 AM
  5. Unable to view query in design view
    By vemi007 in forum Queries
    Replies: 7
    Last Post: 01-19-2012, 11:36 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