Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate data returned in a recordset 2

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
GB
Access 2003

I have a recordset that conatins a number of fields that can be null.

I am trying to test if these fields are null, and so can handle them appropriately.

I have tried

if rs.Fields(0) is nothing then
myString = ""
else
myString = rs.Fields(0)
end if

if rs.Fields(0) is null then
myString = ""
else
myString = rs.Fields(0)
end if

and also

if rs.Fields(0).Length < 1 then
myString = ""
else
myString = rs.Fields(0)
end if

but none of them work. the first 2 just seem to evalutate as false, even when there is no data in that field, and so the code then tries to allocate a null value to my string

the last one always seems to return a length of > 0

So

How do I test specific fields in each row of the recordset to see if they actually contain a value?

K
 
If it's really Null, use the IsNull function

[tt]if IsNull(rs.Fields(0).value) then
myString = ""
else
myString = rs.Fields(0)
end if[/tt]

But you could also use this shortcut

[tt]myString = rs.Fields(0).value & vbnullstring[/tt]

i e concatenate Null with zls ;-)

Roy-Vidar
 
Cheers both, I think its in and working now (until they test it and break it :-/

Thanks again.

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top