Insert Null Value into Date/Time Field
This simple project will simply insert a null value to a date/time field if the checkbox within DateTimePicker is False.
In order to determine if the Checkbox is true/false you need to use the isNull function.
- Private Sub CmdInsert_Click()
- Dim cn As New Connection
- Dim strSQL As String
- cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Data.mdb;"
- strSQL = "INSERT INTO NOSOld (Name, Specialization, Date_of_NOS, Date_Encoded, Case_Officer, Notes, Status) " _
- & "VALUES ('MORENO, JOSAPED', 'HACKER', " & IIf(IsNull(DTPicker1), "Null", DTPicker1.Value) & ", " & IIf(IsNull(DTPicker2), "Null", DTPicker2.Value) & ", 'AVECILLA, PAUL VINCENT', 'ENCODED BY SEM', 'OLD')"
- Debug.Print strSQL
- cn.Execute strSQL
- MsgBox "Record inserted successfully...", vbInformation
- End Sub
I created this sample project to answer the question of shaolin at https://www.sourcecodester.com/forum/inserting-a-null-value-dtpicker-ms-access-db-with-a-datetime-field-type.
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.