Results 1 to 6 of 6

Thread: Invalid use of null

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Freehold, New Jersey, USA
    Posts
    1
    I'm trying to create a sample connection to the Nwind.mdb through code. All connections are fine until I encounter a record that has a blank field. I get an error as soon as I encounter this. Am I supposed to be coding for invalid use of null ? If so, could someone give an example ? TIA

  2. #2
    Junior Member
    Join Date
    Mar 2000
    Posts
    29
    text1.text = rs!Name & ""

    if the rs!Name (or any other variable) is null then adding "" to it will make it a blank string instead.

    or use IsNull(rs!Name) to check if it is null before trying to assign it to a textbox etc

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    iif function

    you also can use the iif function like...

    text1.text = iif(IsNull(.Field(0)),"",.Field(0))

  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    IIF's should be used sparingly, if at all. They are slow, they always evaluate both conditions and if one side fails (even if it's not the side passing evaluation), the whole statement fails.

  5. #5
    Hyperactive Member
    Join Date
    May 1999
    Location
    Reynosa, Mexico
    Posts
    274
    Another simple way is using the trim function:

    Code:
    Text1.Text = Trim("" & rs!Name)
    Good Look!

    Ulises Vázquez
    [size=1.7]Oracle DBA Certified Professioanl
    Visual Basic 6 Developer
    Crystal Reports Designer
    [/size]

  6. #6
    Addicted Member pardede's Avatar
    Join Date
    Jan 2000
    Posts
    232
    you don't even have to use the trim:
    Text1.Text = "" & rs!Name

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