Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    2

    Unanswered: Invalid Use of Null

    I am getting the "Invalid use of Null" message when I execute the following code under the following conditions.

    fields in SQL Server table
    db_date varchar(30) --> "December 29"
    db_subject varchar(200) --> "Test Subject"
    db_thought text --> "This is a test to see if this works"

    I execute the following code from VB6

    strText = "select * from db_table where db_date = 'December 29'"
    ors.open strText, dbConnect
    if not ors.eof then
    if not isnull(ors("db_thought")) then
    txtBox1 = ors("db_thought")
    end if
    end if

    Here is my problem. Since there is a value in db_thought the code if not isnull(ors("db_thought")) evaluates to true -- this is what I expect. However when I try to assign the ors("db_thought") to the txBox1 field I get an Invalid use of Null. What am I missing?

    Thanks
    Last edited by mcannjul; 12-29-03 at 19:58.

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    What happens if you change the if statement to:

    if isnull(...) then
    txtField1 = ""
    else
    txtField1 = ...
    end if

    Also, put in a msgbox before the assignment to display the value or look at it in debug mode under locals.

  3. #3
    Join Date
    Dec 2003
    Posts
    2
    Originally posted by rnealejr
    What happens if you change the if statement to:

    if isnull(...) then
    txtField1 = ""
    else
    txtField1 = ...
    end if

    Also, put in a msgbox before the assignment to display the value or look at it in debug mode under locals.
    I tired your suggestion, and I get the same results. It appears that the test to see if there is information in the field is testing to be true, but the attempt to read from the field is saying that the information is null. I have rechecked the database to see if there is valid data in the field and I see data there.

Posting Permissions

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