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

Nz(variant[, valueifnull]) - Just thought of this 2 minutes ago, wondering if anyone else has ever considered. it...

MLH
A97 HELP shows the proper syntax for using Nz as
Nz(variant[, valueifnull])
I'm wondering what to expect from potential past
misuse I've made. For example, consider the following...

Private Sub Command0_Click()
Dim a As Long, b As String
b = Nz(a, "")
MsgBox b
End Sub

a is clearly not a variant, but the Nz function doesn't
really seem to care too much about that fact. I mean,
I get no errors. But that doesn't mean it couldn't be
causing me a problem.

Granted, I've only thought about this for 2 minutes.
But if its of interest to you and if you have time, I
would appreciate your input. Thx.
Nov 13 '05 #1
8 2157

"MLH" <CR**@NorthState.net> wrote in message
news:59********************************@4ax.com...
A97 HELP shows the proper syntax for using Nz as
Nz(variant[, valueifnull])
I'm wondering what to expect from potential past
misuse I've made. For example, consider the following...

Private Sub Command0_Click()
Dim a As Long, b As String
b = Nz(a, "")
MsgBox b
End Sub

a is clearly not a variant, but the Nz function doesn't
really seem to care too much about that fact. I mean,
I get no errors. But that doesn't mean it couldn't be
causing me a problem.

Granted, I've only thought about this for 2 minutes.
But if its of interest to you and if you have time, I
would appreciate your input. Thx.


You might want to view that syntax example as meaning there is no point to
putting anything other than a variant in the Nz command. In the little
procedure that you posted above, the Nz is absolutely meaningless. a is
dimmed as a Long. A Long can never, under any circumstances, be Null.

Randy

Nov 13 '05 #2
MLH
True enough. A variant is the only thing that can be.
Does anyone ever put an expression (in place of variant)
in there - perhaps one that might evaluate to Null...
DLookUp("[UName]","tblMyData","[MyID] = -1") where
[MyID] is an AutoNumber field? Or, would that also be
a misuse of the Nz syntax?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You might want to view that syntax example as meaning there is no point to
putting anything other than a variant in the Nz command. In the little
procedure that you posted above, the Nz is absolutely meaningless. a is
dimmed as a Long. A Long can never, under any circumstances, be Null.

Randy


Nov 13 '05 #3
MLH wrote:
True enough. A variant is the only thing that can be.
Does anyone ever put an expression (in place of variant)
in there - perhaps one that might evaluate to Null...
DLookUp("[UName]","tblMyData","[MyID] = -1") where
[MyID] is an AutoNumber field? Or, would that also be
a misuse of the Nz syntax?


DLookup() will return Null if no records match so using Nz() is appropriate with DLookup.

Dim sName As String
sName = Nz(DLookUp("[UName]","tblMyData","[MyID] = -1"), "<NotFound>")

Here if the name is not found the DLookup() returns Null and the Nz() function then
returns "<NotFound>" and that value is assigned to the String variable sName.

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #4
> Does anyone ever put an expression (in place of variant)

dim n as long
n = nz(eval("fn()"))

Access 2000, eval converts empty to null, and Nz
without a second parameter converts null back to empty.

(Of course you loose any true null result from the function)

Dim MyFunction(v as variant) as variant
'v is a variant, even if MyFunction was called
'with a string or long parameter: MyFunction(5)
'you can't go the other way: if v is declared as long
'you can't pass a variant parameter
end function

(david)
"MLH" <CR**@NorthState.net> wrote in message
news:s9********************************@4ax.com...
True enough. A variant is the only thing that can be.
Does anyone ever put an expression (in place of variant)
in there - perhaps one that might evaluate to Null...
DLookUp("[UName]","tblMyData","[MyID] = -1") where
[MyID] is an AutoNumber field? Or, would that also be
a misuse of the Nz syntax?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You might want to view that syntax example as meaning there is no point to
putting anything other than a variant in the Nz command. In the little
procedure that you posted above, the Nz is absolutely meaningless. a is
dimmed as a Long. A Long can never, under any circumstances, be Null.

Randy

Nov 13 '05 #5

"MLH" <CR**@NorthState.net> wrote in message
news:s9********************************@4ax.com...
True enough. A variant is the only thing that can be.
Does anyone ever put an expression (in place of variant)
in there - perhaps one that might evaluate to Null...
DLookUp("[UName]","tblMyData","[MyID] = -1") where
[MyID] is an AutoNumber field? Or, would that also be
a misuse of the Nz syntax?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You might want to view that syntax example as meaning there is no point toputting anything other than a variant in the Nz command. In the little
procedure that you posted above, the Nz is absolutely meaningless. a is
dimmed as a Long. A Long can never, under any circumstances, be Null.

Randy


Yes. I frequently put DLookUp inside a Nz. Using Nz I can safely assign
the output of a DLookup to a Long or String variable. Otherwise I would
need to assign the output to a variant, then test for Null before assigning
to another datatype.

Nov 13 '05 #6
MLH
Many thx to all you folks.
I've found a new toy.
Will begin playing henceforth.
Nov 13 '05 #7
Bri

If you think about it you will realize that DLookup MUST be returning
a Variant as it could be returning data from a field of any type.

--
Bri

MLH wrote:
True enough. A variant is the only thing that can be.
Does anyone ever put an expression (in place of variant)
in there - perhaps one that might evaluate to Null...
DLookUp("[UName]","tblMyData","[MyID] = -1") where
[MyID] is an AutoNumber field? Or, would that also be
a misuse of the Nz syntax?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

You might want to view that syntax example as meaning there is no point to
putting anything other than a variant in the Nz command. In the little
procedure that you posted above, the Nz is absolutely meaningless. a is
dimmed as a Long. A Long can never, under any circumstances, be Null.

Randy


Nov 13 '05 #8
MLH
Yeah. That makes sense.
xxxxxxxxxxxxxxxxxxxxxxxxxx
On Fri, 21 Oct 2005 20:32:38 GMT, Bri <no*@here.com> wrote:

If you think about it you will realize that DLookup MUST be returning
a Variant as it could be returning data from a field of any type.


Nov 13 '05 #9

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

Similar topics

2
by: Pink Panther | last post by:
Using the following SQL can the results be explained? Using A97 (with the SP2 for Jet 3.5) or A2002 CREATE TABLE Test (PK Number CONSTRAINT PK_TEST PRIMARY KEY, ParentID Number, Child...
7
by: John Baker | last post by:
Hi: I have seen reference to NZ here numeri\ous times, and since my help function is sort of clobbered I don't have any idea what it really does. Can someone point me in he right direction to...
4
by: Jean | last post by:
Hi all, I am trying to get this query right, but so far no joy... I have written the following code in the Field box of the QBD grid of a query: firstvalue:IIf(Not (IsNull()),,(IIf(Not...
37
by: MLH | last post by:
For example: Nz(,0) returns "300" if the value in field is 300 (currency data type) and "0" if the value is zero or null. I get strings in the query output - they are all left aligned and I...
42
by: lylefair | last post by:
The file is now available as http://www.ffdba.com/downloads/testingNZ3.dat (rename .dat to .mdb) or http://www.ffdba.com/downloads/testingNZ3.mdb (At time of posting I have not opened the file.)
4
by: Paul | last post by:
Anyone have code that emulates the Nz function in Microsoft Access? In Access it is: Nz(Value as variant, Optional ValueIfNull as Variant) as Variant
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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
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,...
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.