CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  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
    Fox Lake, IL
    Posts
    15,007

    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
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  10. #10
    Join Date
    Jun 2019
    Posts
    1

    Re: How to make a date Variable empty ?

    Quote Originally Posted by DataMiser View Post
    I just can't understand why someone would register on a site to replay to a question that was asked 14 years ago ???
    Agreed, makes no sense to me. :-)

  11. #11
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: How to make a date Variable empty ?

    Two negatives don't always result in a positive!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured