DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: vbNull stores 12/31/1899 in Date

  1. #1
    Join Date
    Jan 2005
    Location
    USA
    Posts
    87

    Question vbNull stores 12/31/1899 in Date

    Hi

    I have a date/time field in the SQL database and my VB form has a textbox to enter a date.

    When user hits the Save button on th form,

    If IsDate(Text1.Text) = True Then
    Adodc1.Recordset.Fields("DATE_SENT") = Text1.Text
    Else
    Adodc1.Recordset.Fields("DATE_SENT") = vbNull
    End If

    The record save properly. But when I open the table in database, I can see the date saved as 12/31/1899 if user leaves textbox empty (vbNull).


    To retrieve the record, I use following code and it works fine.

    If Adodc1.Recordset.Fields("DATE_SENT") = vbNull Then
    Text1.Text = ""
    Else
    Text1.Text = Adodc1.Recordset.Fields("DATE_SENT")
    End If


    The problem is that when reports are run by other programs on that table, it shows 12/31/1899 in the date instead of NULL.

    How to avoid this?

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try typing the following in VB's Immediate Window:

    ? vbNull

    As you can see, vbNull is a constant equal to 1; I don't think that's what you intend to assign to your date column. ;-)

    Try changing your code to this:
    Code:
    If IsDate(Text1.Text) = True Then
        Adodc1.Recordset.Fields("DATE_SENT") = Text1.Text 
    Else
        Adodc1.Recordset.Fields("DATE_SENT") = Null
    End If
    
    If Adodc1.Recordset.Fields("DATE_SENT") = Null Then
        Text1.Text = ""
    Else
        Text1.Text = Adodc1.Recordset.Fields("DATE_SENT")
    End If
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Jan 2005
    Location
    USA
    Posts
    87
    Haha

    How stupid can one be Thanks Phil


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center