Solved

Setting Dates to Null?

Posted on 1998-09-03
2
177 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
2 Comments
 

Author Comment

by:Zv
Comment Utility
Edited text of question
0
 
LVL 2

Accepted Solution

by:
percosolator earned 200 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now