Problem detecting Null

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • corepaul@aol.com

    #1

    Problem detecting Null

    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

    #2
    Re: Problem detecting Null

    On Thu, 13 Apr 2006 16:26:54 GMT, corepaul@aol.co m 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

    Comment

    • corepaul@aol.com

      #3
      Re: Problem detecting Null


      On 13-Apr-2006, fredg <fgutkind@examp le.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 =---

      Comment

      • Bob Quintal

        #4
        Re: Problem detecting Null

        corepaul@aol.co m wrote in
        news:1144945321 _471@sp6iad.sup erfeed.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.

        Comment

        • Terry Kreft

          #5
          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@sympa tico.ca> wrote in message
          news:Xns97A4B4E BC4C68BQuintal@ 207.35.177.135. ..[color=blue]
          > corepaul@aol.co m wrote in
          > news:1144945321 _471@sp6iad.sup erfeed.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]


          Comment

          • Bob Quintal

            #6
            Re: Problem detecting Null

            "Terry Kreft" <terry.kreft@mp s.co.uk> wrote in
            news:9LmcnQsOQo aha6LZSa8jmw@ka roo.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.

            Comment

            Working...