Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/168837

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 15:34, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Article ID: 168837

Article Last Modified on 10/11/2006


  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 4.0 Professional Edition
  • Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition

This article was previously published under Q168837


Trying to set a Visual FoxPro Date field to Null via DAO/ODBC results in the following error:

"Run-time error '3162':

Null Is Invalid."


The FoxPro ODBC driver does not use Null for an empty date.


Set the date field to 12/30/1899 instead. The Visual FoxPro ODBC driver translates this value into an empty date.


This behavior is by design.


In Visual Basic and other VBA and DAO applications, dates are stored as the number of days since 12/30/1899. This date is stored internally as the number 0. The Visual FoxPro ODBC driver takes this 0 value to represent an empty date.

Steps to Reproduce Behavior

  1. Create and execute the following Visual FoxPro program:

          CREATE DATABASE ztest
          CREATE TABLE ztest (dfield d)
          APPEND BLANK
          REPLACE dfield WITH {3/15/96}
  2. In Visual FoxPro, modify the Database "ztest" and add the table "ztest" to the database. Add an additional character field and create a Primary Key (this is required for the ODBC driver to write back to the table). Exit Visual FoxPro and create a Visual FoxPro data source called ztest, which points to the database ZTEST.DBC.
  3. Create a new Visual Basic or VBA project. Make sure that Microsoft DAO 3.0 or 3.5 object library is included in your References.
  4. Add the following code to a Module:

          Sub Test_VFP_Date()
          Dim db As Database, rs As Recordset
            Set db = OpenDatabase("", False, False, _
            Set rs = db.OpenRecordset("ztest")
            rs!dfield = Null
          End Sub
  5. Run the code from the Immediate Window. If prompted for ODBC connection information, select the ztest data source. Then, select the ztest table and click OK.
  6. You will receive the run-time error described above for the line:

    rs!dfield = Null

  7. Change the line to either:

    rs!dfield = #12/30/1899#


    rs!dfield = 0

    and rerun the application.
  8. Open the ztest table in Visual FoxPro to verify the date is now blank.


Keywords: kb32bitonly kberrmsg kbprb kbprogramming KB168837