Need help testing NULL fields

MoMo
07-11-2002, 11:37 AM
Hello,

I'm a bit stumped. Using an access database to read back a buttload of data, but some of the fields are NULL. Here's an example of the code i'm using, followed by the error.


<%
If objRS("Email_Accounts") = Null Then
Response.Write "No Email Accounts for this domain..."
Else
Response.Write Replace(objRS("Email_Accounts"),vbcrlf,"<br>")
End If
%>


Here's the error i'm getting:
Microsoft VBScript runtime (0x800A005E)
Invalid use of Null: 'Replace'
/view_account.asp, line 90

It's obviously hitting my Else statement, but why? The value is Null, I know this. Is my IF statement constructed wrong? Thanks in advance for any help.

Thinker
07-11-2002, 11:44 AM
You can't use = Null, you have to use something like...
If objRS("Email_Accounts") Is Null Then
or
If objRS(Email_Accounts") & "" = "" Then

MoMo
07-11-2002, 12:44 PM
Thanks a bunch. The second line of code worked. The first one (If objRS(Email_Accounts") Is Null Then) I had tried before and got an error saying object required. No matter, i'll use the other. :)

Thanks again.

Rezner
07-11-2002, 04:23 PM
Or... what I like to do, so as to "naturalize" the code a bit. I use a function called "IsBlank":
Public Function IsBlank(varMe as Variant) As Boolean
IsBlank = IsNull(varMe) Or _
IsEmpty(varMe) Or varMe = "" Or Len(varMe) = 0
End FunctionHere, you pretty much are guarenteed to see if the variable really has "nothing" in it. (That is, if you don't mind using a Variant.)

Thinker
07-11-2002, 04:35 PM
This at least clears up my wondering if the IsNull function was
available in VBScript.

Don't worry about variants in VBScript - They are all variants.

Rezner
07-11-2002, 04:46 PM
Originally posted by Thinker
This at least clears up my wondering if the IsNull function was
available in VBScript.

Don't worry about variants in VBScript - They are all variants. Whoops... you know what? I *forgot* that I was in the ASP forum. So, for ASP (VBScript) you'd want to make a slight modification to the above function since, like Thinker said, everything is of type Variant:
Public Function IsBlank(varMe)
IsBlank = IsNull(varMe) Or _
IsEmpty(varMe) Or varMe = "" Or Len(varMe) = 0
End Function

Robby
07-11-2002, 04:49 PM
Never mind, Rezner fixed it. ( I figured that you didn't realize you were in the ASP forum)

MoMo
07-11-2002, 05:01 PM
hehe, thanks. I'll give those a try as well.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum