473,396 Members | 2,076 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,396 software developers and data experts.

Blank record in query produces "#Error"

In my Fleet Management Application, I'm pulling together three separate queries to then calculate Total Average Cost Per Mile for each Vehicle.
I have a total of 52 active vehicles. Some or all of them may be returned as part of the following queries:

1. Vehicle Gas Cost Per Mile (40 vehicle records)
2. Vehicle Maintenance Cost Per Mile (37 vehicle records)
3. Vehicle Overhead Cost Per Mile (52 vehicle records)

I have a Query that is JustVIDs containing bridges to all the different Primary Keys (V_ID, VIN, Gas Card).

The problem is that if no gas record exists, the query returns #Error. Not all vehicles have Maintenance records, but a blank record there just results in blank. This is what I want gas to do, but it will not. I've tried NZ, IIF...

I can post the SQL if that will help, but due to all the calculations involved in getting to the final Cost per Mile for gas, there are 3 queries. Everything is fine, until I try to force Gas to display a blank if there are no records for that V_ID.

I hope I've stated this clearly. I've tried very hard. Please ask if something is confusing. Thank you.
Mar 15 '11 #1
4 11753
code green
1,726 Expert 1GB
I'm the guessing the query does some calculations,
but where no record exists, the calculation is done on a NULL value.
Try an extra filter
Expand|Select|Wrap|Line Numbers
  1. AND [field] IS NOT NULL
This can be in the WHERE clause or ON condition in JOIN
Mar 15 '11 #2
My problem with trying to evaluate for null is that the field never evaluates to null because it does not exist for that record. What I really seem to need is "If [Avg Gas Cost Per Mile] is nothing"
Mar 15 '11 #3
Here's what I finally got to work:
IIf([__costCalc_JustVIDs].[V_ID]=[_costGasCalc1_qryCostPerMile].[V_ID],[Avg Cost per Gallon]/[MPG],0)
Mar 15 '11 #4
NeoPa
32,556 Expert Mod 16PB
I suspect Code Green is bang on the money here. Somewhere along the line (It's hard to say where as we don't have all the SQL to hand - and if we did I guess it might be pretty complicated anyway) something is calculating with a Null or zero value that can't handle that. Division by zero is a particularly frequently occurring problem when a query is designed with a certain set of data then later is called into play to handle situations where the data is either different or not even there (which in many cases - OUTER JOINs specifically - means that the data referenced simply arrives as a Null).

I suspect a careful checking of the query known to have problems, with the idea in your mind that you may be dealing with Null data, would turn up the culprit. Alternatively, checking the value available as you do, can also work. It may leave you exposed later if you subsequently want to use the query in a similar way, but you should be equally able to bypass the problem at that stage if it does.
Mar 16 '11 #5

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

Similar topics

8
by: Matt | last post by:
Hi all, Thank you for taking the time. I have a database with 45 tables on it. 44 tables are linked to a main table through a one to one relationship. My question is, is there no way i can...
2
by: noname | last post by:
I have a query that subtracts this months mileage from last months, then divides that mileage value by the fuel used by the vehicle to figure this months miles per gallon. Whenever one of the...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
2
by: christianlott1 | last post by:
I'm doing a replace function on a phone number field: Expr1: NZ(ReplaceText(),"") and it converts most of them but for others I get this "#Error" in the fields. Since I will need to do a join...
6
AccessIdiot
by: AccessIdiot | last post by:
Hi all, I have this function in an unbound textbox on my form: =DSum("SpecimenCount","tbl_Specimen_Entrainment","Entrainment_ID = " & ) It does a wonderful job, except when I go to a new...
4
by: lostlander | last post by:
In ARMCC, and Microsoft C, when i use a function which is never defined or delared, it gives out a warning, not a compiling error? why? (This leads to a bug to my program since I seldom pay much...
6
kcdoell
by: kcdoell | last post by:
Hello: I three fields on a continuous form: , & On the same form I have an unbound text box with the following formula in the control source: =Sum(IIf(=50,,0)) This worked great.
2
by: Lewe22 | last post by:
I am wondering if anyone knows a way of representing a "#Error" shown on a form in a text box as 0? I realise this is not the most logical thing to do but does anyone know if it's possible....
7
govnah
by: govnah | last post by:
Hi mighty fine people, I have a report with two sub-reports attached. The Main report calculates the totals of the two sub-reports. The problem i am having is that when i open the report, it...
6
sueb
by: sueb | last post by:
I have a split database, which was functioning fine at close of business yesterday. This morning, all date fields show "#ERROR", and moving from one record to the next gives the following pop-up...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
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...
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...

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.