By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,155 Members | 2,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,155 IT Pros & Developers. It's quick & easy.

DateDiff NULL - Type Mismatch Error

P: n/a
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_Name = Me.IDNO.Column(1) & ", " & Me.IDNO.Column(2)
Me.DOH = Me.IDNO.Column(20)
Me.Recruit_Class = 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_Service.value = YOS

Dec 28 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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_Name = Me.IDNO.Column(1) & ", " & Me.IDNO.Column(2)
Me.DOH = Me.IDNO.Column(20)
Me.Recruit_Class = 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_Service.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
Dec 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.