473,506 Members | 16,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling DateDiff() with blank date fields

7 of 9
23 New Member
OK here is my code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Select Case DateDiff("D", Shipdt, Date)
  3.     Case Is > 90
  4.         WTAge = "GT-90"
  5.     Case Is > 60
  6.         WTAge = "61-90"
  7.     Case Is > 30
  8.         WTAge = "31-60"
  9.     Case Is < 31
  10.         WTAge = "LT-31"
  11. End Select
  12.  
  13.  
Im using the code to create an aging report for orders. the code tells me if the order shipped > 90, 61-90, 31-60, or >31 days ago but what if the order has not shipped. In that case that field would be blank and would cause an error. How do I handle empty date fields?
Jan 22 '09 #1
2 3645
puppydogbuddy
1,923 Recognized Expert Top Contributor
Dates in date fields are stored as numbers, so the nz function is used to convert nulls to 0 as shown.

nz([Datefield], 0)

You should then add a case statement for the value of 0.
Case Is 0
Exit Select (or maybe Exit Sub)
Jan 22 '09 #2
missinglinq
3,532 Recognized Expert Specialist
This should handle having nothing in the field, and something similar should probably be included in all Select Case constructs, to handle the unexpected:

Expand|Select|Wrap|Line Numbers
  1. Select Case DateDiff("D", Shipdt, Date)
  2.     Case Is > 90
  3.         WTAge = "GT-90"
  4.     Case Is > 60
  5.         WTAge = "61-90"
  6.     Case Is > 30
  7.         WTAge = "31-60"
  8.     Case Is < 31
  9.         WTAge = "LT-31"
  10.     Case Else
  11.         WTAge = ""
  12.  End Select
And please refrain from using an existing thread to post a separate question. Your question about DateDiff() has nothing to do with the original thread. Doing this is known as "thread hijacking" and against the rules, both here and on most technical forums.

I've moved it to its own thread.

Linq ;0)>

Moderator
Jan 22 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11904
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...
2
2269
by: PMBragg | last post by:
Thank you in advance. I'm trying to pull all inventory items from December of the previous year back to 4 years for my accountant. I know this can be done, but I'm drawing a blank. I've tried; ...
1
4966
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
1
2832
by: info | last post by:
Can some one show me how to use the datediff function where the dates are being supplied through an access db. For instance, a recordset would contain these fields: DateAssigned, DateDue,...
3
3329
by: T23Ij9 | last post by:
Hi. I have 3 seperate date fields. InitialDate InspDate ReportDate I am trying to setup several unbound Text boxes in a form that will give me days elapsed between these dates. These text...
1
2005
by: John T. | last post by:
I have two date fields: InitialDate InspDate I've tried to use a Datediff expression within an IIF function (see below) in an unbound textbox to give me the amount of days elapsed between...
1
1616
by: Geoff | last post by:
I have 2 date fields on a form called FirstDate and SecondDate. The gap between these 2 dates should always be more than a week. I have set a validation rule, through the properties screen, on...
5
2582
by: green51 | last post by:
hi In the below command I like to know can I combine it with the IIf function. I am checking to see if NSCHD is blank. If it is blank I would place "no date" in the place of the result.. "Starts...
6
4343
by: Wheeler2008 | last post by:
Hi All, I am currently running a query on a MS Access table, in which I want to be able to compare and total the difference in dates between records. I only have one date field within the table. ...
0
7220
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
7308
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
7371
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
7023
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
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5037
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
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
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.