Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Convert null date to today's date (XP)

    I am trying to convert a missing date in a query into today's date in a query. I have written the following Function "MissingDate".
    I keep getting #Error when the date is missing. I have included an example database.

    Function MissingDate(FieldofMissingDate As Date)

    If FieldofMissingDate = Null Then
    MissingDate = Now()
    Else
    MissingDate = FieldofMissingDate
    End If

    End Function

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Convert null date to today's date (XP)

    Instead of this function, use the expression

    Nz([FieldName],Now())

    If you want to use the function, you must define FieldOfMissingDate as a variant, since a Date variable can't be Null.

    Function MissingDate(FieldofMissingDate As Variant) As Date
    If IsNull(FieldofMissingDate) Then
    MissingDate = Now()
    Else
    MissingDate = FieldofMissingDate
    End If
    End Function

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert null date to today's date (XP)

    Thank you. Now all I have to do is to Format it in Short Date.

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Convert null date to today's date (XP)

    Unless you specifically needed the time, I'd use Date() instead of Now() in Hans expression.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Mishawaka, Indiana, USA
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Convert null date to today's date (XP)

    Thank you, that is a good idea.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •