Results 1 to 5 of 5

Thread: How to check if date is null

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    211

    How to check if date is null

    hi

    this is my code, and its not working,the way it should be

    Code:
    Code:
    if rs!start_ded=0 then 
    exit sub 
    else
    rs!start_ded=format(now,"mm/dd/yyyy")
    what i want is to check if the rs!start_ded empty then do nothing else format(now,"mm/dd/yyyy"). i don't know what to put in if rs!start_ded=0

    thanks!

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to check if date is null

    pick a record you know has an empty date and return the field to a messagebox or something
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    441

    Re: How to check if date is null

    yes as westconn1 told you return a record from your database and check it's value when date is empty to know what is it's format...Once done, you can compare it easily

    For example in vb if you declare a date variable and you want to check if it's empty or not, you can do something like

    vb Code:
    1. if MyDate = "00:00:00" then
    2.  msgbox "Empty Date"
    3. Else
    4.  msgbox "Not Empty"
    5. End if


    In your case you'd better check what are the values of empty dates in your database and then you make comparaison

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: How to check if date is null

    Code:
    if IsNull(rs!start_ded) then
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to check if date is null

    Or
    vb Code:
    1. If Not IsNull(rs!start_ded) Then
    2.     rs!start_ded=format(now,"mm/dd/yyyy")
    3. End If

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