1
votes

Am trying to insert date from a table to another table using vba in access, But one of the date values from the table is blank. So while inserting the date to new table it shows Invalid use of null exception Run-time error 94.

4

4 Answers

2
votes

If writing DAO code to clear a Date field, I found that I had to use "Empty". Null and "" won't work. So for field dtmDelivery (type Date), I had to use the following. strDelivery is just a string with the date in it.

Set rst = dbs.OpenRecordset("tblSomething", dbOpenDynaset)
If (strDelivery = "") Then                      
    rst!dtmDelivery = Empty    
Else 
    rst!dtmDelivery = strDelivery
End If

rst.Update
0
votes

you can use the NZ() function to define a value that should be used instead of NULL. Internally a date is a float value where the number represents the days between 01.01.1900 and the date that should be stored. The part behind the decimal point represents hours/minutes (.25 for example is 6 AM). So you can use the NZ() funtion to replace NULL bei 0 (what would be interpreted as 01.01.1900).

Another solution would be to configure the target table in a way that it allows NULL values. You can do this easily in the design view of the table.

0
votes

I think i figure it out , declare the variable to string. Then check whether value from the table is empty, then assign null to it.Other wise assign the value from the table.

for example

   Dim newdate As String

Check whether the fetched values is null or not

   If IsNull(rst![value]) Then
            newdate = "null"
   Else
           newdate = rst![value]
   End If     
0
votes

I encountered this problem and solved it this way.

SQL = "update mytable set mydatefield = '" & txtdate & "'"

On the txtdate on your form, put a date format to ensure date is either a real date or just blank.