• We just launched and are currently in beta. Join us as we build and grow the community.

Insert Null Value into Date/Time Field

FurFighter123

Arena Tactician
F Rep
0
0
0
Rep
0
F Vouches
0
0
0
Vouches
0
Posts
130
Likes
184
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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.

  1. Private

    Sub

    CmdInsert_Click()
  2. Dim

    cn As

    New

    Connection
  3. Dim

    strSQL As

    String

  4. cn.Open

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

    & App.Path & "\Data.mdb;"

  5. strSQL = "INSERT INTO NOSOld (Name, Specialization, Date_of_NOS, Date_Encoded, Case_Officer, Notes, Status) "

    _
  6. & "VALUES ('MORENO, JOSAPED', 'HACKER', "

    & IIf(IsNull(DTPicker1), "Null"

    , DTPicker1.Value) & ", "

    & IIf(IsNull(DTPicker2), "Null"

    , DTPicker2.Value) & ", 'AVECILLA, PAUL VINCENT', 'ENCODED BY SEM', 'OLD')"

  7. Debug.Print

    strSQL

  8. cn.Execute strSQL

  9. MsgBox "Record inserted successfully..."

    , vbInformation
  10. End

    Sub

I created this sample project to answer the question of shaolin at http://www.sourcecodester.com/forum...icker-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.

 

452,292

323,341

323,350

Top