Solved

Setting Dates to Null?

Posted on 1998-09-03
2
182 Views
Last Modified: 2010-04-30
Using VB5 (RDO) and MS SQL Server, how do you set a datetime field on the database from a valid date to Null?
0
Comment
Question by:Zv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:Zv
ID: 1432834
Edited text of question
0
 
LVL 2

Accepted Solution

by:
percosolator earned 200 total points
ID: 1432835
There are two ways that I can immediately think of, one using an action query, the second, opening up a recordset and setting the field to null.

--------------------------------------
Option Explicit

Dim env As rdoEnvironment
Dim rdc As rdoConnection

Private Sub Command1_Click()

    'action query
    Dim SQL As String
   
    SQL = "UPDATE tblCustomers SET DateEntered = NULL WHERE CustomerID = 1061"
    rdc.Execute SQL, rdExecDirect
   
   
End Sub

Private Sub Command2_Click()

    Dim SQL As String
   
    Dim rd As rdoResultset
   
    SQL = "SELECT *" & _
        " FROM tblCustomers" & _
        " WHERE CustomerID = 1061"
       
    Set rd = rdc.OpenResultset(SQL, rdOpenDynamic, rdConcurLock)
   
    If (Not (rd.BOF And rd.EOF)) Then
   
        rd.Edit
        rd!DateEntered = Null
        rd.Update
       
    End If
   
    rd.Close
   
End Sub

Private Sub Form_Load()


    Set env = rdoEnvironments(0)
   
    Set rdc = env.OpenConnection("ODBC", , , "DSN=TEST;UID=SA;PWD=;DATABASE=TEST")
       
End Sub
------------------------------

which ever method you choose is up to you

advantages:

          Command1's method will be faster, but if the field you are updating (not in your case) might have apostrophes or quotation marks in it, then you are going to have a problem with unclosed quotes.

          Command2's method has no problem with quotations, but is going to be a hair slower.


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 2 hours left to enroll

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question