DateDiff NULL - Type Mismatch Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    #1

    DateDiff NULL - Type Mismatch Error

    I have a function which caculates the number of years from a certain
    date. The function works great if the date is not null however when
    the date is null I recieve a type mismatch error. The code is below.
    Any assistance is appreciated. Thanks!!

    Dim YOS As String

    Me.date1 = Year(Me.Injury_ Date)
    Me.Employee_Nam e = Me.IDNO.Column( 1) & ", " & Me.IDNO.Column( 2)
    Me.DOH = Me.IDNO.Column( 20)
    Me.Recruit_Clas s = Me.IDNO.Column( 19)
    YOS = DateDiff("yyyy" , [DOH], Date) - IIf(Format(Date , "mmdd") <
    Format([DOH], "mmdd"), 1, 0) 'breaks here on null of DOH
    Me.Years_of_Ser vice.value = YOS

  • Rick Brandt

    #2
    Re: DateDiff NULL - Type Mismatch Error

    Mike wrote:
    I have a function which caculates the number of years from a certain
    date. The function works great if the date is not null however when
    the date is null I recieve a type mismatch error. The code is below.
    Any assistance is appreciated. Thanks!!
    >
    Dim YOS As String
    >
    Me.date1 = Year(Me.Injury_ Date)
    Me.Employee_Nam e = Me.IDNO.Column( 1) & ", " & Me.IDNO.Column( 2)
    Me.DOH = Me.IDNO.Column( 20)
    Me.Recruit_Clas s = Me.IDNO.Column( 19)
    YOS = DateDiff("yyyy" , [DOH], Date) - IIf(Format(Date , "mmdd") <
    Format([DOH], "mmdd"), 1, 0) 'breaks here on null of DOH
    Me.Years_of_Ser vice.value = YOS
    So test for Null at the top of the code and do whatever you deem appropriate
    when Null is detected.

    --
    Rick Brandt, Microsoft Access MVP
    Email (as appropriate) to...
    RBrandt at Hunter dot com


    Comment

    Working...