Wednesday, March 28, 2012

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?

ThanksWhat 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.|||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.

No comments:

Post a Comment