Solved

Setting Dates to Null?

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

832 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