There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop malware monitor motherboard mouse network networking outlook 2007 power printer problem ram router screen slow sound spyware trojan usb virus vista vista 32-bit windows windows xp windowsxp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Problem Handling Nulls


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
coachdan32's Avatar
Computer Specs
Senior Member with 1,000 posts.
 
Join Date: Nov 2003
Location: Louisville, KY
02-Jun-2004, 09:36 AM #1
Question Problem Handling Nulls
I am having problems with a report page that shows monthly stats for our trainers. The numbers are entered into an Access DB weekly and this report should report a running total on the stats, but when the trainer has no stats entered on one of the weeks it is calculating their schedule adhereance as 0. Trainers that have stats on all weeks work fine. The SQL statement I have attempts to take a total of all weeks (production hours) and divide it by a total of all weeks (scheduled hours) - so in theory if one week is null, it shouldn't matter. There must be something wrong in the syntax though because it is not working. Here is the line that calculates that:

Code:
SQLSP = SQLSP & " ((Sum([StdtProdAS]![W1ProdHrs]+[StdtProdAS]![W2ProdHrs]+[StdtProdAS]![W3ProdHrs]+[StdtProdAS]![W4ProdHrs]))/(Sum([StdtProdAS]![W1AdjSchedHrs]+[StdtProdAS]![W2AdjSchedHrs]+[StdtProdAS]![W3AdjSchedHrs]+[StdtProdAS]![W4AdjSchedHrs]))) AS SA, "
There is also a data validation check to handle null values:

Code:
If MArT(6,x) > 0 Then
varSA = FormatPercent(MArT(6,x))
Else
varSA = 0
End If
Can anyone spot anything wrong or offer a better way to get around this problem?
__________________
CoachDan
http://www.malehsbaseball.com

Gateway Pentium 4 3.0 GHz
200G Sata HD
800 FSB
512 DDR
DVD +-R/W
XP Home
Rockn's Avatar
Computer Specs
Distinguished Member with 17,888 posts.
 
Join Date: Jul 2001
Location: Mexico of the North, MN
Experience: Disenfranchised American Male
02-Jun-2004, 10:04 AM #2
You need to find a way to convert your fields to zero if they are null prior to adding them.
coachdan32's Avatar
Computer Specs
Senior Member with 1,000 posts.
 
Join Date: Nov 2003
Location: Louisville, KY
03-Jun-2004, 09:33 AM #3
I changed the SQL statement, but I have a problem with the parenthesis grouping. I did the front half of the statement (before the "/" sign) first and it worked. After I did the other half I got the error message returning the SQL code. Can anyone spot a problem?

Code:
SQLSP = SQLSP & " Sum(IIf([StdtProdAS]![W1ProdHrs]>0,[StdtProdAS]![W1ProdHrs],0)+IIf([StdtProdAS]![W2ProdHrs]>0,[StdtProdAS]![W2ProdHrs],0)+IIf([StdtProdAS]![W3ProdHrs]>0,[StdtProdAS]![W3ProdHrs],0)+IIf([StdtProdAS]![W4ProdHrs]>0,[StdtProdAS]![W4ProdHrs],0))/(Sum(IIf([StdtProdAS]![W1AdjSchedHrs]>0,[StdtProdAS]![W1AdjSchedHrs],0))+IIf([StdtProdAS]![W2AdjSchedHrs]>0,[StdtProdAS]![W2AdjSchedHrs],0))+IIf([StdtProdAS]![W3AdjSchedHrs]>0,[StdtProdAS]![W3AdjSchedHrs],0))+IIf([StdtProdAS]![W4AdjSchedHrs]>0,[StdtProdAS]![W4AdjSchedHrs],0))))) AS SA, "
Rockn's Avatar
Computer Specs
Distinguished Member with 17,888 posts.
 
Join Date: Jul 2001
Location: Mexico of the North, MN
Experience: Disenfranchised American Male
03-Jun-2004, 02:07 PM #4
I thought you were testing for Nulls not >0

Try this:
IIF(ISNull([StdtProdAS]![W1ProdHrs],0,[StdtProdAS]![W1ProdHrs]))

Still seems like a lot of coding for converting Nulls to 0

How about creating a variable for each field in the database and just add up the variables.
coltsfan's Avatar
Junior Member with 22 posts.
 
Join Date: Sep 2001
Location: Central Indiana
05-Jun-2004, 12:11 AM #5
I am assuming that the data is being entered via an Access Form. If so then the problem is that the form uses a textbox for entry of your numeric value.

Edit the properties of the textbox and set the default value to 0. This will handle the string to single/double conversions which take place and eliminate the storing of null values in your fields.

This should fix the problem. But you should still check the denominator's sum for > 0 to avoid 'divide by 0' errors.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:55 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.