473,800 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Null field values & isnull function

I have a query that has null values for some of the fields. I'd like
those fields to display a zero instead of a blank so I can do totals
on them (sum/totalling the field is not working with null values) I
created a function as follows...

Function zeros(ethfield As Integer) As Integer

If IsNull(ethfield ) Then
zeros = 0
Else
zeros = ethfield
End If
End Function

I'm getting a #error for the fields with nulls, and the non-null
fields are returning the correct data. Any idea of what I'm doing
wrong or a different approach for converting the null values to zeros?

Sep 18 '07 #1
2 2627
"Coll" <co*********@ho tmail.comwrote in message
news:11******** **************@ 57g2000hsv.goog legroups.com...
>I have a query that has null values for some of the fields. I'd like
those fields to display a zero instead of a blank so I can do totals
on them (sum/totalling the field is not working with null values) I
created a function as follows...

Function zeros(ethfield As Integer) As Integer

If IsNull(ethfield ) Then
zeros = 0
Else
zeros = ethfield
End If
End Function

I'm getting a #error for the fields with nulls, and the non-null
fields are returning the correct data. Any idea of what I'm doing
wrong or a different approach for converting the null values to zeros?
Why not use the built-in Nz function?
As in:
Nz([ethfield],0)
Fred Zuckerman
Sep 18 '07 #2

"Coll" <co*********@ho tmail.comwrote in message
news:11******** **************@ 57g2000hsv.goog legroups.com...
I have a query that has null values for some of the fields. I'd like
those fields to display a zero instead of a blank so I can do totals
on them (sum/totalling the field is not working with null values) I
created a function as follows...

Function zeros(ethfield As Integer) As Integer

If IsNull(ethfield ) Then
zeros = 0
Else
zeros = ethfield
End If
End Function

I'm getting a #error for the fields with nulls, and the non-null
fields are returning the correct data. Any idea of what I'm doing
wrong or a different approach for converting the null values to zeros?

You are getting a error because you defined ethfield as an Integer instead
of a Variant.
..
Sep 18 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
5566
by: scott | last post by:
i've come across a real head-hurter. I'm looping through a recordset and response.writing it's rows out with no problem except 1 field. The field type is varchar and contains words like meeting, holiday, etc. Problem is, I'm trying to render a "n/a" when the field is null as in LISTING 1 below. My code isn't catching the null values. How can I test for null values? I could swear I've successfully used the Len() test like below...
8
10412
by: Lyn | last post by:
I am trying to get my head around the concept of default, special or empty values that appear in Access VBA, depending on data type. The Access Help is not much (help), and the manual that I have is not much help here either. Googling has given me a little help. This is my current understanding -- I would appreciate any comments or corrections... "" -- this means an empty string when applied to String data type, and also to Variant...
7
40029
by: Dan | last post by:
I'm fairly new to C# and I am having some problems understanding int variables and null values. I have created a class that populates the values of it's fields from a DataReader in it's constructor. Those fields are modified during various methods in the class. One method updates the database with the values of the class fields. I have everything working fine for string fields but am running into problems with integers and null values.
2
3998
by: Stuart | last post by:
Hi there I have a stored procedure on my SQL database that retrieves a wide range of values from about 5 different tables. My end point is to calculate the cost against each line of retrieved data. Depending upon the contents of a particular field that cost calculation changes.... I retrieve the data in to a dataset and subsequently in to a datatable - fine so far...
2
4437
by: ILCSP | last post by:
Hello, I'm in the process of changing our 'normal' Access 2000 update queries to Update Pass Through Queries. We have a SQL server 2000 database and we're using an Access 2000 database as our front end. In the criteria of one of our update query fields, we use both the isnull(field1) and Not IsNull(field2) then Field3, otherwise, set the updated field as null. Here's my converted Pass Through Query : UPDATE Vsel SET VSel.Cert1 =...
4
32741
by: Shwetabh | last post by:
Hi, My question is, is there any difference between a NULL and a Blank (Unknown, Not Applicable) field in MS SQL or are they the same? Awaiting your comments, Regards
3
12320
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero (0) length string, an empty Field, or no value at all - so exactly what is Null? The purpose of this Topic is hopefully to explain what a Null Value is, discuss some peculiarities about Nulls, show how we can detect them, and finally, how to convert...
5
2808
by: iwasinnihon | last post by:
I have written the following SQL to take data off of a form and insert it into a table. sql = "INSERT INTO Water Values('" & Me.AccountNumber & "','" & Me.Department & "','" & Me.Delivery & "','" & Me.IndexCode & "','" & Me.ContactPerson & "','" & Me.ContactExt & "','" & Me.Canceled & "',#" & Me.AddDate & "#,#" & Me.CancelDate & "#,'" & Me.Fiscal_Year & "');" It works fine if there is a date in the CancelDate field, but if the date is...
0
3070
prabirchoudhury
by: prabirchoudhury | last post by:
CRITERIA; +-------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+-------+ | CritCode | int(4) | NO | PRI | 0 | | | Description | varchar(150) | YES | | NULL | | | CritGroup | varchar(10) | YES | | NULL | | | Detail | varchar(30) | YES | | NULL | ...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10276
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
10253
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
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
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
5471
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...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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.