473,804 Members | 3,797 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 3675
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
11920
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 STARTINGDATE1 ENDINGDATE1 STARTINGDATE2
2
2282
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; DateDiff("y",-4,DateIn) and get errors Please any assistance would be greatly appreciated. Michael
1
4985
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 blank. I've tried; > >DateDiff("y",-4,DateIn) and get errors > >Please any assistance would be greatly appreciated. >
1
2847
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, ProjectName, ProjectDetail, Class. The student enters a project name, then a date it was assigned and a date it is due...and other details about the project into the appropriate fields. The projects appear in a databound list box...when you click on a...
3
3356
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 boxes act like message boards to alert the user if the days elapsed have exceeded a certain amount of
1
2167
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 InitialDate and current date: - after 6 days have elapsed from the InitialDate and - only if the InspDate field is empty.
1
1631
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 the FirstDate field so that when this first date is entered it compares to the second date =DateDiff("ww",,)>1
5
2603
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 In " & DateDiff("d",Format(Date(),"mm/dd"),Format(,"mm/dd")) & " Days" Thanks bg
6
4382
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. The table contains the following fields: Acc. Number Transaction Date Detail Current Balance Everytime another transaction is completed, the current balance will change. However, a transaction will not be completed every day (it is ad-hoc)...
0
10593
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7626
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4304
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 we have to send another system
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3000
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.