CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 1999
    Location
    Brighton, MI
    Posts
    3

    Nulls in a Date field

    I need to load null values into a MSACCESS date field defined as DATETIME and my VB program is blowing up with an error code 3421 - Data type conversion error. Is there anyway to load null values into a field defined this way?

    Regards,

    Luanne Benedict

  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Nulls in a Date field

    Have you actually tried using the Null Value? ,e.g.

    private Sub Command1_Click()
    Dim oDB as Database
    Dim oRS as Recordset
    set oDB = Workspaces(0).OpenDatabase("DB1.mdb")
    set oRS = oDB.OpenRecordset("SELECT * FROM Table1 WHERE ID=0", dbOpenDynaset)
    oRS.AddNew
    oRS("DateTimeField") = null
    oRS.Update
    set oRS = nothing
    oDB.Close
    set oDB = nothing
    End Sub





    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  3. #3
    Join Date
    Nov 1999
    Location
    Brighton, MI
    Posts
    3

    Re: Nulls in a Date field

    No I hadn't tried that, but I did and it worked great. Why would rs.[datefield] = "" not work?

    Regards,

    Luanne Benedict

  4. #4
    Join Date
    Oct 1999
    Posts
    12

    Re: Nulls in a Date field

    Luanne,

    Because "" is not null, it's an empty string. Which are two entirely different things to Access. Date fields in Access will not accept an empty string...


  5. #5
    Join Date
    Nov 1999
    Location
    Brighton, MI
    Posts
    3

    Re: Nulls in a Date field

    Thank you both for your help. It's much appreciated!

    Regards,

    Luanne Benedict

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured