473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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_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
1 3846
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Arun Wadhawan | last post by:
Hello MY SQL Server is causing me this problem : Microsoft VBScript runtime error '800a000d' Type mismatch: 'ident' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> I am getting from...
1
by: LJgrnl | last post by:
I've got a type mismatch error that's driving me nutty. Variable blnNoData has the initial value False. If a recordset comes back empty (both .EOF and ..BOF are true) then blnNoData is set to...
4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
1
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. ...
6
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The...
3
by: ZhaoYingpu | last post by:
Hello,all I am using win32com to use com. and invoke a method as follows: void AddShapeInfo(LPCTSTR name, LONG type, IDispatch* pDisp); but i pass 0 or None to third parameter and get error info:...
1
by: green51 | last post by:
hi I am trying to get a list of name who's birthday is 35 of days away. I have build a query with all of the information the I need. Under the field birth I enter the following criteria:...
6
by: samuel84 | last post by:
Hi, I am getting the error "invalid use of null" when summing value from a range which has no value and "data type mismatch in criteria expression" when there are values to be summed up. Is there...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.