How to make a date Variable empty ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: How to make a date Variable empty ?

  1. #1
    Guest

    How to make a date Variable empty ?

    How can I make a date variable assigned empty like we do with strings by setting ""



  2. #2
    Join Date
    Aug 1999
    Location
    India-Delhi
    Posts
    106

    Re: How to make a date Variable empty ?

    Hi,

    Use NULL to assing a blank in date field.

    or alternatively -
    in INSERT INTO statement do not include the date fields, it will automatically be blank.



    Santulan

  3. #3
    Join Date
    Oct 1999
    Posts
    11

    Re: How to make a date Variable empty ?

    My problem is as below regarding dates

    Dim StartDate as Date

    StartDate = #10/01/1999#

    ...
    ...
    ...

    Now I want to make the variable empty

    I tried to issue null

    StartDate = Null

    '' Giving Error

    Check out this



  4. #4
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: How to make a date Variable empty ?

    use vbNull

    RK

  5. #5
    Join Date
    Aug 1999
    Location
    India-Delhi
    Posts
    106

    Re: How to make a date Variable empty ?

    In access if you update and set date = "" date gets blank.
    or you try vbNull

    Santulan

  6. #6
    Join Date
    Dec 2010
    Posts
    2

    Re: How to make a date Variable empty ?

    I realize I'm writing this 11 years after the initial query, but the advice given is erroneous, and so I'm adding this so others who see this page are not misled. vbNull is intended strictly for use with the VarType() function to test if a variable is Null, as follows:

    If VarType(abc) = vbNull Then

    You cannot use vbNull to set a variable to Null. Indeed, if you try it, like so:

    abc = vbNull

    then the variable will actually be assigned a value of 1 (or "1" if it's a string variable). So if you do that then obviously an IsNull() test would fail to work properly because the variable is not null.

    My understanding is that for a code variable you can't actually assign a Null to it unless it's a Variant data type (unlike an Access table field, which you can assign as Null). So a string variable must be assigned as empty string and a numeric must be assigned zero (or whatever else you want to used to signify as "unassigned" in the logical context of your code), like so:

    str = ""
    num = 0

  7. #7
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: How to make a date Variable empty ?

    Why dig up long-dead posts?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    Aug 2013
    Posts
    1

    Re: How to make a date Variable empty ?

    Reply to Your Query - Solved
    If you declare any variable as date format, it will the data like as "00:00:00".
    So before execute your sql command , please verify the contents in the date varaible as follws
    If isdate(Var_date) = True or Var_date <> "00:00:00" Then
    Tablename!Fieldname = Var_Date
    else
    TableName!FieldName =Empty
    End if

    recordset.update

    I tried the above method, it works with MsAccess and MSSQL too

    Thank You

  9. #9
    DataMiser is online now Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,835

    Re: How to make a date Variable empty ?

    I just can't understand why someone would register on a site to replay to a question that was asked 14 years ago ???
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center