How to Pass Null Date

Results 1 to 2 of 2

Thread: How to Pass Null Date

  1. #1
    Join Date
    Dec 1969

    Default How to Pass Null Date

    In my Access table, I have a field formatted as date/time. Sometimes the date field on the form my users fill out does not need to be filled in. However, when I attempt to post to the database script that writes the rest of the data, I get a mismatch error for the date field. How can I allow the users to skip over this field if they need to?

  2. #2
    Join Date
    Dec 1969

    Default Using keyword NULL

    I recommend doing this:<BR><BR>&#060;%<BR>Function ISODate( dt )<BR> If IsDate(dt) Then<BR> dt = CDate(dt) &#039; safety<BR> &#039; change the # characters to apostrophes for any DB except Access<BR> ISODate = "#" & Year(dt) & "-" & Month(dt) & "-" & Day(dt) & "#"<BR> Else<BR> ISODate = "NULL"<BR> End If<BR>End Function<BR>%&#062;<BR><BR>ANd then build your SQL string like this:<BR><BR>&#060;%<BR>SQL = "INSERT INTO table ( someDateField ) " _<BR> & " VALUES( " & ISODate(Request("formFieldWithDatePerhaps")) & ")"<BR>%&#062;<BR><BR>[The alternative is to simply leave the field *OUT* of the INSERT, but often that&#039;s more code than what I show.]<BR><BR>

Posting Permissions

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