• Convert null date to today’s date (XP)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Convert null date to today’s date (XP)

    Author
    Topic
    #428098

    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

    Viewing 1 reply thread
    Author
    Replies
    • #993650

      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

      • #993664

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

    • #993674

      Unless you specifically needed the time, I’d use Date() instead of Now() in Hans expression.

    Viewing 1 reply thread
    Reply To: Convert null date to today’s date (XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: