Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem detecting Null

corepaul@aol.com
Guest
 
Posts: n/a
#1: Apr 13 '06
I am using Acess 2000 and Windows 2000.

I have a form with a text box txLName. tStrGlobal As String is dimensioned
globally. The first time I enter the text box, the Enter event with the code

If txLName.Value = Null Then
tStrGlobal = ""
Else
tStrGlobal = txLName.Value ' error occurs in this line
End If

causes an "Invalid use of null" error in the assignment statement after the
Else statement. Why doesn't the If statement correctly detect the Null?

The following code works fine

If txLName.Value <> Null Then
tStrGlobal = txLName.Value
Else
tStrGlobal = ""
End If

I'm not stuck, so please reply at your convenience. I'm just trying to
better understand how Access works. I'm a relative newbie.

Paul Core


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

fredg
Guest
 
Posts: n/a
#2: Apr 13 '06

re: Problem detecting Null


On Thu, 13 Apr 2006 16:26:54 GMT, corepaul@aol.com wrote:
[color=blue]
> I am using Acess 2000 and Windows 2000.
>
> I have a form with a text box txLName. tStrGlobal As String is dimensioned
> globally. The first time I enter the text box, the Enter event with the code
>
> If txLName.Value = Null Then
> tStrGlobal = ""
> Else
> tStrGlobal = txLName.Value ' error occurs in this line
> End If
>
> causes an "Invalid use of null" error in the assignment statement after the
> Else statement. Why doesn't the If statement correctly detect the Null?
>
> The following code works fine
>
> If txLName.Value <> Null Then
> tStrGlobal = txLName.Value
> Else
> tStrGlobal = ""
> End If
>
> I'm not stuck, so please reply at your convenience. I'm just trying to
> better understand how Access works. I'm a relative newbie.
>
> Paul Core
>
> ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
> http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
> ---= East/West-Coast Server Farms - Total Privacy via Encryption =---[/color]

Use:

If IsNull(txLName) Then



--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
corepaul@aol.com
Guest
 
Posts: n/a
#3: Apr 13 '06

re: Problem detecting Null



On 13-Apr-2006, fredg <fgutkind@example.invalid> wrote:
[color=blue][color=green]
> > I am using Acess 2000 and Windows 2000.
> >
> > I have a form with a text box txLName. tStrGlobal As String is
> > dimensioned
> > globally. The first time I enter the text box, the Enter event with the
> > code
> >
> > If txLName.Value = Null Then
> > tStrGlobal = ""
> > Else
> > tStrGlobal = txLName.Value ' error occurs in this line
> > End If
> >
> > causes an "Invalid use of null" error in the assignment statement after
> > the Else statement. Why doesn't the If statement correctly detect the
> > Null?[/color][/color]
[color=blue]
>
> Use:
>
> If IsNull(txLName) Then[/color]

Thanks, this works as intended.

Paul


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Bob Quintal
Guest
 
Posts: n/a
#4: Apr 13 '06

re: Problem detecting Null


corepaul@aol.com wrote in
news:1144945321_471@sp6iad.superfeed.net:
[color=blue]
> I have a form with a text box txLName. tStrGlobal As String is
> dimensioned globally. The first time I enter the text box, the
> Enter event with the code
>
> If txLName.Value = Null Then
>[/color]
Nulls are strange beasts.
See http://allenbrowne.com/casu-02.html

Part of the null issue is that (x = null) will evaluate FALSE if x
contains any value and null if x is null. It will never evaluate to
true.



always test using isnull(x) in VBA or where x is null IN sql ,
--
Bob Quintal

PA is y I've altered my email address.
Terry Kreft
Guest
 
Posts: n/a
#5: Apr 14 '06

re: Problem detecting Null


Null propagates so (x = Null) returns Null, no matter the value of x

e.g.
Dim x
x = Null
Debug.Print IsNull(x = Null)
x = 1
Debug.Print IsNull(x = Null)

Result
True
True

--

Terry Kreft


"Bob Quintal" <rquintal@sympatico.ca> wrote in message
news:Xns97A4B4EBC4C68BQuintal@207.35.177.135...[color=blue]
> corepaul@aol.com wrote in
> news:1144945321_471@sp6iad.superfeed.net:
>[color=green]
> > I have a form with a text box txLName. tStrGlobal As String is
> > dimensioned globally. The first time I enter the text box, the
> > Enter event with the code
> >
> > If txLName.Value = Null Then
> >[/color]
> Nulls are strange beasts.
> See http://allenbrowne.com/casu-02.html
>
> Part of the null issue is that (x = null) will evaluate FALSE if x
> contains any value and null if x is null. It will never evaluate to
> true.
>
>
>
> always test using isnull(x) in VBA or where x is null IN sql ,
> --
> Bob Quintal
>
> PA is y I've altered my email address.[/color]


Bob Quintal
Guest
 
Posts: n/a
#6: Apr 14 '06

re: Problem detecting Null


"Terry Kreft" <terry.kreft@mps.co.uk> wrote in
news:9LmcnQsOQoaha6LZSa8jmw@karoo.co.uk:
[color=blue]
> Null propagates so (x = Null) returns Null, no matter the
> value of x
>[/color]

That's what I think i meant to say..
[color=blue]
> e.g.
> Dim x
> x = Null
> Debug.Print IsNull(x = Null)
> x = 1
> Debug.Print IsNull(x = Null)
>
> Result
> True
> True
>[/color]



--
Bob Quintal

PA is y I've altered my email address.
Closed Thread


Similar Microsoft Access / VBA bytes