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 http://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.

Comments
help admin
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)
example:
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: undying_emolove@yahoo.com
urgent need sir. sna matulongan moko yan nlnag kulang sa thesis q :)
re: help admin
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.
tnx
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
Add new comment