Re: trying to use null but getting no where



Thanks Tom that did the trick.
I read that only variants could have null assigned to them but I did
not see what you had posted....and on a Friday too LOL

thanks again


On Fri, 21 Mar 2008 09:44:02 -0700, Tom van Stiphout
<no.spam.tom7744@xxxxxxx> wrote:

On Fri, 21 Mar 2008 15:44:00 GMT, sparks <sparks@xxxxxxxxxxx> wrote:

You're making several mistakes.
First off, in VBA only variants can be null. Integers, strings, etc.
cannot.
This is all legal:
Dim v As Variant
v = Null
v = SomeFunctionReturningNull()
v = Me.Controls(x).Value
v = myRecordset.Fields(x).Value
If I change v to be an integer, the above is all illegal and "Invalid
use of null" will occur.

Second, note how I assigned a value of Null to v:
v = Null
not " IsNull (res) "

If you want to test if some variable is null, you use IsNull:
if IsNull(v) then
Msgbox "It's Null!"
else
Msgbox "It's " & v
end if

A stylistic point: try to avoid double negation. I like my last code
block better than:
if not IsNull(v) then
Msgbox "It's " & v
else
'Twist my brain: it's not not null.
Msgbox "It's Null!"
end if

-Tom.


in access 203 I am passsing some variables to a fuction and then
calculating on them and passing off this to another function.
my problem comes with the nulls




I am passing some values and strings to different functions


one problem I need to define a vaiable as int


dim res as integer

but when I do this


If Not IsNull(Me.Controls(str4).Value) Then

res = Me.Controls(str4).Value

Else

IsNull (res)

End If


if the control is null then res should be null

but res = 0


the only thing I can find is that res should be a variant

then I run into a problem that passing to the next function


If Not IsNull(ageck) And Not IsNull(wt) And Not IsNull(res) And Not
IsNull(pos) Then ' And Not IsNull(val2) Then

ckstuff2 ageck, wt, res, pos, val2


it looks as res and sure enough res (a variant) = 0


should I do something like this on the variable to define a null to a
99 so I can then look at it or what I am not sure what to do and don't
want to start replacing values.

iif(isnull(res),99,res)

.



Relevant Pages

  • Re: Parameters in events
    ... > Private Sub object_ProjectBeforeResourceChange2(ByVal res As ... > MSProject.Resource, ByVal Field As PjField, ByVal NewVal As Variant, ByVal ...
    (microsoft.public.project.vba)
  • Re: Vlookup syntax format
    ... Dim myDate As Date ... Dim res As Variant ... What I read was that Microsoft wasn't putting VBA with the latest Mac ...
    (microsoft.public.excel.programming)
  • Re: trying to use null but getting no where
    ... Dim v As Variant ... not " IsNull (res) " ... Msgbox "It's Null!" ...
    (comp.databases.ms-access)
  • Re: Writing a Boolean Statement Parser/Engine - Need help
    ... Dim Eval As CEval, Expression As String, ResAs Variant, i as Long ... Walters and so on are one dim arrays of Booleans. ...
    (microsoft.public.vb.general.discussion)
  • Re: vlookup
    ... Function tazAs Variant ... Dim res As Variant ... taz = "Error in c,d,e,f!" ...
    (microsoft.public.excel.programming)