Skip to main content

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

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 for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


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.


Submitted bycedon Sat, 10/23/2010 - 16:25

sir.. i need ur help abwt. dtpicker.

If Weekday(DTPicker1.Value) = vbSunday Then
MsgBox "sun"
End If

that sample abobe used to determine if the selected date is sunday or saturday wat i want is
how can i avoid/skip recording saturday-sunday. i mean in recording that days..

I need this in my application. (Leave Slip)

i have 2 dtpicker (start and end)
I will leave from October 20 - 26 2010

dtpickerstart = 20
dtpickerEnd = 26

how can i avoid/skip 23,24? the report will be like this.
I have an idea using loop and if else but cant get it. please help.

Oct.20 - LEAVE
Oct.21 - LEAVE
Oct.22 - LEAVE
Oct.25 - LEAVE

email: [email protected]
urgent need sir. sna matulongan moko yan nlnag kulang sa thesis q :)

Submitted byadminon Sat, 10/23/2010 - 17:26

I'm using this kind of code in my library system. The system will skip saturday and sunday for calculating Fines.

I will get back to you as soon as I have time.

Submitted byAnonymous (not verified)on Sat, 10/23/2010 - 21:26

In reply to by admin

tnx sir ill post my own code if successful.. I need it also for my DTR.. GoodLuck Sir. I wait for ur answer. :)

-Cedrick Blas

Submitted byVinod Pareek (not verified)on Sat, 02/22/2014 - 17:12

Thank you Sir !!! I spent lots of time to find solution for this problem and finally I found your Post. Its 100% working sir !! thanks A lot.

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.