473,394 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Using Nz with Format + CDate + HH:nn:ss problem

547 512MB
The following code does not ignore the empty field values.It provides the correct values when the fields do contain a time value (ie 10:20:35)
Expand|Select|Wrap|Line Numbers
  1. TotalTime3: Format$(Nz(CDate([lap1time]))+Nz(CDate([lap2time]))+Nz(CDate([lap3time]))+Nz(CDate([lap4time])),"hh:nn:ss")
(for illustration purposes i used the first 4 fields only - are actually 8)
Any suggestion on how to ignore empty fields in this query please?
Attached Images
File Type: jpg nz1.jpg (26.6 KB, 349 views)
Nov 27 '10 #1
7 3694
MMcCarthy
14,534 Expert Mod 8TB
You are not using the NZ function correctly. The function is nz(CDate([lap1time]),"Value if Null").

However, in this case I don't think you need it. If the field values are null then just using the + sign should deal with it.

Expand|Select|Wrap|Line Numbers
  1. TotalTime3: Format$(CDate([lap1time])+CDate([lap2time])+CDate([lap3time])+CDate([lap4time]),"hh:nn:ss")
Nov 27 '10 #2
neelsfer
547 512MB
The timefield values are blank as it is generated in a query. I need to use
Expand|Select|Wrap|Line Numbers
  1. TotalTime3: Format$(Nz(CDate([lap1time]))+Nz(CDate([lap2time]))+Nz(CDate([lap3time]))+Nz(CDate([lap4time])),"hh:nn:ss")
and incorporate Nz or equivalent to compensate for the blank values. Any suggestions please?
Nov 27 '10 #3
MMcCarthy
14,534 Expert Mod 8TB
Did you try using 0 for the value is null property?

Expand|Select|Wrap|Line Numbers
  1. TotalTime3: Format$(Nz(CDate([lap1time]),0)+Nz(CDate([lap2time]),0)+Nz(CDate([lap3time]),0)+Nz(CDate([lap4time]),0),"hh:nn:ss")
I'm not sure I understand why the + sign on it's own doesn't work though, it should just ignore the null values.
Nov 27 '10 #4
neelsfer
547 512MB
this is so weird!
if i have lap1time to lap4time and no blank spaces, it works 100%
If i have only 3x laptimes and 1 blank space, it gives an error
see pics
Attached Images
File Type: jpg 4 spacescode.jpg (21.2 KB, 339 views)
File Type: jpg 4spacesfilled.jpg (32.5 KB, 299 views)
File Type: jpg 1emptyspace.jpg (29.4 KB, 206 views)
Nov 27 '10 #5
ADezii
8,834 Expert 8TB
You are a victim of NULL Propagation, without using Nz(), if any part of an Expression evaluates to NULL, the entire expression will return NULL as in:
Expand|Select|Wrap|Line Numbers
  1. Format$(CDate("00:51:54") + NULL + CDate("00:00:03"), "hh:nn:ss")
Returns:
Expand|Select|Wrap|Line Numbers
  1. NULL
Nov 27 '10 #6
neelsfer
547 512MB
Any solution you may have in mind?
This sounds like a serious cancer to me!
Nov 27 '10 #7
ADezii
8,834 Expert 8TB
Here is the Loooooooooooong answer for 5 Laps, I had to leave some fun for you! (LOL).
Expand|Select|Wrap|Line Numbers
  1. TotalTime: Format$(IIf(IsNull([LapTime1]),0,CDate([LapTime1]))+IIf(IsNull([LapTime2]),0,CDate([LapTime2]))+IIf(IsNull([LapTime3]),0,CDate([LapTime3]))+IIf(IsNull([LapTime4]),0,CDate([LapTime4]))+IIf(IsNull([LapTime5]),0,CDate([LapTime5])),"hh:nn:ss")
Nov 27 '10 #8

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

Similar topics

3
by: Harry J. | last post by:
Hello All; We are trying to build a table for tracking times on the Physical Fitness test. Part of the test is the time it takes to swim so many laps or to run a mile distance. Access has...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
11
by: Lauren Quantrell | last post by:
I already figured out (the hard way) I need to convert all my date parameters into USA format before executing my stored procedures where dates are used as parameters. (Format(StartDate, "m/d/yyyy...
16
by: Filips Benoit | last post by:
Dear all, I have a datefield that sometimes should store hours and minutes too ans use following format and inputmask. dd/mm/yyyy hh\:nn 09/09/0000\ 99:99;0;* Typing date, hour and...
26
by: Tom Becker | last post by:
Is there a way, from Access, to programmatically click the Send and Receive button in Outlook?
18
by: Shawn Yates | last post by:
I have a report that looks up the earliest start time in a query . Right now it opens up the query and grabs the earliest start date like it should. This is the working code: Set rs =...
5
by: Killer42 | last post by:
Hi all. I have a query which calculates the difference between two date/time fields. This returns a number which is, of course, useless without formatting (“I couldn’t believe it took...
45
by: Killer42 | last post by:
Hi all. Lunch time now, so I can spare a few minutes to throw in a question before my 2 hour meeting. Can someone show me briefly how, from VBA, to set up a query with columns formatted the way...
8
by: John | last post by:
Hi I am using the below code to run a sql on an underlying access table; insStr = "INSERT INTO ( Action, , , Request_Date ) " & _ "VALUES (""Modify Client"", 93, ""Administrator"", Now())"...
4
by: T | last post by:
-------------------------------------------------------------------------------- I tried this audit trail code, using 2003 and it works great, I try and use it at work w/97 and it blows up:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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...

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.