Link to home
Start Free TrialLog in
Avatar of gianitoo
gianitoo

asked on

Invalid use of Null: 'CStr'

get this error when my checkbox is empty.   how can i change code

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'CStr'

/accountpropertyinfo.asp, line 123


<input <%If (CStr((Recordset1.Fields.Item("ClosestBase").Value)) = CStr("1")) Then Response.Write("checked") : Response.Write("")%> name="single" type="checkbox" id="single" value="1">
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SquareHead
SquareHead

<% If Not(IsNull(Recordset1.Fields.Item("ClosestBase").Value) or Recordset1.Fields.Item("ClosestBase").Value = "") then

If (CStr((Recordset1.Fields.Item("ClosestBase").Value)) = CStr("1")) Then Response.Write("checked") : Response.Write("")%> name="single" type="checkbox" id="single" value="1">

<%
end if %>
Try:

<% IF NOT IsNull Recordset1("ClosestBase") THEN%>
<input <%If (CStr((Recordset1.Fields.Item("ClosestBase").Value)) = CStr("1")) Then Response.Write("checked") : Response.Write("")%> name="single" type="checkbox" id="single" value="1">
<%End IF%>

There are more elegant ways of doing it, but that should get you going.

bvinson
As I said, there are more elegant ways, and I think amit_g probably has one of the more elegant methods.  I would, however suggest that in his page you put the function before the code that calls it rather than just "somewhere".  Sometimes ASP will stumble if you call a function before its loaded, especially if you don't have response.buffer = true.

bvinson
Thank you [amit_g]
Your code would out great for me this evening.

have a good one.
Carrzkiss