Null a date field in a recordset

  • I'm returning a recordset using DAO that contains a date field. In some instances (like a date value is more than 1 year old), I want to null the field in the recordset.


    I've tried !Date = vbNull, but all that does is enter 12/31/1899 in the field. I want it to be null. Any suggestions?

  • Re: Null a date field in a recordset


    I think that your vbNull is effectively putting a zero in the cell which Excel will interpret as 1 Jan 1900 (or apparently 31 Dec 1899 in your case). Try Clearcontents instead. Something like:

    Code
    Sub ClearYearOldDates()
    Dim c As Range
    For Each c In Selection
        If Date - c > 365 Then c.ClearContents
    Next c
    End Sub
  • Re: Null a date field in a recordset


    The date is a field in a database, not in a cell. I need the equivalent of clearcontents or null in DAO terminology.


    I need something to the effect of:

    Code
    with rs1
    .edit
    !Date = vbNull  or rs1.fields("Date") = vbNull
    .update
    end with
  • Re: Null a date field in a recordset


    Hello again Norie. You've bailed me out so many times. By returning the recordset, do you mean to get into the form, or returning it to the database?

  • Re: Null a date field in a recordset


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!