Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2004
    Posts
    5

    Unanswered: DateDiff Problem

    Hi,

    The problem I am having concerns the DateDiff function. I have the code to get it to work but not all of my date fields have dates in them. The error that comes up reads "Invalid use of null". How can I correct this problem with dates missing. Below is the code I am using.

    Function DateDiffW(BegDate, EndDate)
    Const SUNDAY = 1
    Const SATURDAY = 7
    Dim NumWeeks As Integer

    If BegDate > EndDate Then
    DateDiffW = 0
    Else
    Select Case Weekday(BegDate)
    Case SUNDAY: BegDate = BegDate + 1
    Case SATURDAY: BegDate = BegDate + 2
    End Select
    Select Case Weekday(EndDate)
    Case SUNDAY: EndDate = EndDate - 2
    Case SATURDAY: EndDate = EndDate - 1
    End Select
    NumWeeks = DateDiff("ww", BegDate, EndDate)
    DateDiffW = NumWeeks * 5 + Weekday(EndDate) - Weekday(BegDate) + 1
    End If

    End Function

    Confused and needing help,

    flem671

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    What do you want it to do if there's a missing date?
    Back to Access ... ADO is not the way to go for speed ...

  3. #3
    Join Date
    Oct 2004
    Posts
    5

    RE: DateDiff Problem

    Return a value of 0. The same as if the begdate > enddate then
    datediffw = 0. Everything I try still comes up with an error.

  4. #4
    Join Date
    Oct 2004
    Posts
    5
    Return a value of 0. The same as if the begdate > enddate then
    datediffw = 0. Everything I try still comes up with an error.

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by flem671
    Return a value of 0. The same as if the begdate > enddate then
    datediffw = 0. Everything I try still comes up with an error.
    Ok ...

    If IsNull(BegDate) Or IsNull(EndDate) Then
    DateDiffW=0
    exit function
    endif

    Next question ...
    Back to Access ... ADO is not the way to go for speed ...

  6. #6
    Join Date
    Oct 2004
    Posts
    5
    Thanks. That works great.

Posting Permissions

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