CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Null Dates

  1. #1
    Join Date
    May 2000
    Location
    NH
    Posts
    49

    Null Dates

    I am reading an Access Database and printing records in VB. In some records the date may be blank and this is OK, for example "date shipped", not all orders are shipped yet. When I try to do ANYTHING with the date, i.e. move to a variable, if the date is Null, I get an error. So I test the date to see if there is anything in it. If there isn't I want to make it 0. But when I print it I get 12/30/99. If I date has nothing in it, how can I print it as nothing. It's not on a line by itself, there are several other fields, so it's difficult to not print it if it's blank.

    Thanks

    cruella69

  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Null Dates

    In your SQL select statement which eliminate records with Null dates

    Select * from YourTable where IsDate(DateShipped) = True

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    May 2000
    Location
    NH
    Posts
    49

    Re: Null Dates

    The thing is that I want to print the record and show the other things like ordered date and show a blank shipped date

    cruella69

  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Null Dates

    In this case select all the required records in your SQL. But when you print records check if record is null. For example

    If IsNull(Recordset!ShipDate) then
    Printer.Print ""
    Else
    Printer.Print Recordset!ShipDate
    End If

    Try this if with IsNull and with IsDate, which will suit you better

    Good luck


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  5. #5
    Join Date
    May 2000
    Location
    NH
    Posts
    49

    Re: Null Dates

    What I really need to do is print something like this

    Order# Qty Ord Date Ordered Date Shipped Date Ret.
    1 2 1/1/00 2/1/00 3/1/00
    2 2 2/1/00
    3 3 3/1/00 4/1/00

    The null dates display as 12/31/99 instead of blank. Any ideas?

    cruella69

  6. #6
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Null Dates

    What do you have in you database tabel Null or 12/31/99?

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  7. #7
    Join Date
    May 2000
    Location
    NH
    Posts
    49

    Re: Null Dates

    the dates are blank in the database

    cruella69

  8. #8
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Null Dates

    Try this:
    dim s as string

    If IsNull(Recordset!ShipDate) then
    s=""
    Else
    s = CStr(rs!ShipDate)
    End If

    Printer.Print rs!Order# & rs!Qty & rs!OrdDate & rs!ShipDate & rs!RetDate
    Don't forget to include Spaces or Tabs between columns (I skipped them to be short)

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  9. #9
    Join Date
    May 2000
    Location
    NH
    Posts
    49

    Re: Null Dates

    I finally came up with something that worked for what I needed. I declared a variable as a string, cleared the variable, if there was something in the date field I moved the contents to the string variable, otherwise I left it blank. When I print the string variable it either has something or it is blank.

    Thanks for all your help. I really appreciate it!

    cruella69

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