In reference to an old post in thread 705-300424, I am writing to give my solution for anyone who needs a way to insert Nulls into a Date field in a table.
Here is what I did. I used a VBA Private Sub to accomplish this goal.
In the above code I'm executing this against a form with 2 unbound text fields.
I have a subform within the main form to see the output of my code (hence the requery of the subform).
In my Test Form, I have one text field set with a format of "Short Date", and the other as a plain text with no format.
The table I am inserting the values into has 3 fields. The first field is an ID AutoNumber. The second field is my Date/Time with a format of "Short Date" (for consistency). The third and final field is a Short Text field with a maximum of 25 characters. I have had no issues inserting normal dates of 9/30/2016, or 10/31/2016. There is no reason to reference the AutoNumber field when performing an insert.
I hope this helps anyone out there who is having issues inserting nulls into a date field.
Here is what I did. I used a VBA Private Sub to accomplish this goal.
Code:
Private Sub cmdAdd_Click()
DoCmd.SetWarnings False
DoCmd.RunSQL "INSERT INTO tbl_Test_Date (TestDate, TestText) VALUES (" _
& IIf(IsNull(dtDate), "'" & Null & "'", "#" & dtDate & "#") & ",'" & Me.Text2 & "');"
tbl_Test_Datesubform.Form.Requery
End Sub
In the above code I'm executing this against a form with 2 unbound text fields.
I have a subform within the main form to see the output of my code (hence the requery of the subform).
In my Test Form, I have one text field set with a format of "Short Date", and the other as a plain text with no format.
The table I am inserting the values into has 3 fields. The first field is an ID AutoNumber. The second field is my Date/Time with a format of "Short Date" (for consistency). The third and final field is a Short Text field with a maximum of 25 characters. I have had no issues inserting normal dates of 9/30/2016, or 10/31/2016. There is no reason to reference the AutoNumber field when performing an insert.
I hope this helps anyone out there who is having issues inserting nulls into a date field.