Validation If Null and Empty String

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

    Validation If Null and Empty String

    Are the following two validation the same:
    1) IsNull(Me.Colum nName) and Me.ColumnName = ""
    2) Me.ColumnName """

    It would seem to be better to use: Me.ColumnName """

  • storrboy

    #2
    Re: Validation If Null and Empty String

    On Feb 23, 3:06 pm, "tomleb...@msn. com" <tomleb...@msn. comwrote:
    Are the following two validation the same:
    1) IsNull(Me.Colum nName) and Me.ColumnName = ""
    2) Me.ColumnName """
    >
    It would seem to be better to use: Me.ColumnName """
    No they are not. One tests for a value (empty strings are values) and
    the other sees what of two values is logically greater.
    An empty string is less than a 'normal' string and a numeric variable
    with no value defaults to 0.
    However when doing this and one of the values is Null (mainly when
    using variants) the comparison will always fail because a null has no
    value to test.

    I find the easiest test when you need to know if something is null is
    to use the Nz function. If it is, this function lets you force a
    different value so that your comparison don't fail.

    Comment

    • tomlebold@msn.com

      #3
      Re: Validation If Null and Empty String

      On Feb 23, 2:23 pm, "storrboy" <storr...@sympa tico.cawrote:
      On Feb 23, 3:06 pm, "tomleb...@msn. com" <tomleb...@msn. comwrote:
      >
      Are the following two validation the same:
      1) IsNull(Me.Colum nName) and Me.ColumnName = ""
      2) Me.ColumnName """
      >
      It would seem to be better to use: Me.ColumnName """
      >
      No they are not. One tests for a value (empty strings are values) and
      the other sees what of two values is logically greater.
      An empty string is less than a 'normal' string and a numeric variable
      with no value defaults to 0.
      However when doing this and one of the values is Null (mainly when
      using variants) the comparison will always fail because a null has no
      value to test.
      >
      I find the easiest test when you need to know if something is null is
      to use the Nz function. If it is, this function lets you force a
      different value so that your comparison don't fail.
      What is the recommended syntax to verify if a text box is empty?
      I assume you should check for both nulls and empty string.
      Does Me.Column "" check for both nulls and empty string?

      Comment

      • storrboy

        #4
        Re: Validation If Null and Empty String


        If Nz(Me!txBoxName ,True) Then
        or
        If Nz(Me!txBoxName ,"") = "" then ....
        or
        variable = Nz(Me!txBoxName ,"")

        The last argument is what to return if the value is null. Otherwise
        the actual value is returned.

        Comment

        • Wayne Gillespie

          #5
          Re: Validation If Null and Empty String

          On 23 Feb 2007 12:31:53 -0800, "tomlebold@msn. com" <tomlebold@msn. comwrote:
          >On Feb 23, 2:23 pm, "storrboy" <storr...@sympa tico.cawrote:
          >On Feb 23, 3:06 pm, "tomleb...@msn. com" <tomleb...@msn. comwrote:
          >>
          Are the following two validation the same:
          1) IsNull(Me.Colum nName) and Me.ColumnName = ""
          2) Me.ColumnName """
          >>
          It would seem to be better to use: Me.ColumnName """
          >>
          >No they are not. One tests for a value (empty strings are values) and
          >the other sees what of two values is logically greater.
          >An empty string is less than a 'normal' string and a numeric variable
          >with no value defaults to 0.
          >However when doing this and one of the values is Null (mainly when
          >using variants) the comparison will always fail because a null has no
          >value to test.
          >>
          >I find the easiest test when you need to know if something is null is
          >to use the Nz function. If it is, this function lets you force a
          >different value so that your comparison don't fail.
          >
          >What is the recommended syntax to verify if a text box is empty?
          >I assume you should check for both nulls and empty string.
          >Does Me.Column "" check for both nulls and empty string?
          If Len(Me.MyTextBo x & "") 0 Then ...

          This will catch both Nulls and ZeroLengthStrin gs in one check.


          Wayne Gillespie
          Gosford NSW Australia

          Comment

          • ApexData@gmail.com

            #6
            Re: Validation If Null and Empty String

            I use the following code to check for null and empty string:

            If Len(Nz(Me!txBox Name,"")) = 0 Then

            Comment

            • ApexData@gmail.com

              #7
              Re: Validation If Null and Empty String

              PrettyCool Wayne!
              I hadn't seen that one yet. All with one function

              Comment

              • Wayne Gillespie

                #8
                Re: Validation If Null and Empty String

                On 23 Feb 2007 16:42:13 -0800, "ApexData@gmail .com" <ApexData@gmail .comwrote:
                >PrettyCool Wayne!
                >I hadn't seen that one yet. All with one function
                I think I got it from Lyle from memory.
                Wayne Gillespie
                Gosford NSW Australia

                Comment

                Working...