Results 1 to 8 of 8

Thread: "invalid use of null" error. Makes no sense

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    28

    Arrow "invalid use of null" error. Makes no sense

    If rstTable.Fields(2) = Null Then
    strDescription = " "
    Else
    strDescription = rstTable.Fields(2)
    '"Invalid use of null" error occurs right here. How can this be?
    End If

  2. #2
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Try replacing Null with vbNullString.
    You just proved that sig advertisements work.

  3. #3
    Addicted Member
    Join Date
    Apr 1999
    Posts
    178
    replace

    If rstTable.Fields(2) = Null Then

    with

    if isnull(rstTable.Fields(2) then


    and

    strDescription = rstTable.Fields(2)

    with

    strDescription = rstTable.Fields(2) & ""

  4. #4
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489
    I had a problem like this also. If you are dealing with SQL
    the definition for Null does not work with VB's Definition.
    If none of the previous suggestions work declare a Variable
    of Type Varient. Put the database value in the variable and
    then do your IF statement. That should do it.

  5. #5
    Alain
    Guest

    Use the IsNull command

    You can use:

    If blahblah = Null

    VB Code:
    1. Use If IsNull(blahblah) = true then
    2.  'you got your null
    3. else
    4.  'value is correct
    5. end if

  6. #6
    Alain
    Guest

    Sorry...

    I meant:

    "You can't use:"

  7. #7
    WALDO
    Guest

    That doesn't always work.

    In ASP (VBScript), that won't work. Believe me, I've hit this wall before.

    Try This:
    VB Code:
    1. If Len(rstTable.Fields(2).Value & "") = 0 Then
    2.     strDescription = ""
    3. Else
    4.     strDescription = rstTable.Fields(2).Value
    5. End If

  8. #8
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Just:
    VB Code:
    1. strDescription = "" & rstTable.Fields(2)
    No care about if it's null or not.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width