467,116 Members | 1,196 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,116 developers. It's quick & easy.

IF/Then statement doesn't work

I am sorry about posting such an elementary question, but I just can't
get this to work:

<%if (Recordset1.Fields.Item("notes").Value)="" then%>
<%else%>
<tr><td>Additional notes:
<b><%=(Recordset1.Fields.Item("notes").Value)%></b></td> </tr>
<%end if %>

I just want to say if recordset "notes" is empty, don't do anything.
If it is not, then write <tr><td>Additional notes:
<b><%=(Recordset1.Fields.Item("notes").Value)%></b></td> </tr>

However, the words "Additional notes:" keeps showing up on every page,
regardless of whether "notes" is empty or not.

What am I doing wrong?

thanks in advance, crispy
Jul 19 '05 #1
  • viewed: 1254
Share:
9 Replies
<%
Dim strValue
strValue = (Recordset1.Fields.Item("notes").Value)
If strValue = "" Then
'Do nothing
Else
Response.Write "<tr><td>Additional notes:<b>" & strValue &
"</b></td> </tr>"
End If
%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
<crispy> wrote in message news:hh********************************@4ax.com...
I am sorry about posting such an elementary question, but I just can't
get this to work:

<%if (Recordset1.Fields.Item("notes").Value)="" then%>
<%else%>
<tr><td>Additional notes:
<b><%=(Recordset1.Fields.Item("notes").Value)%></b></td> </tr>
<%end if %>

I just want to say if recordset "notes" is empty, don't do anything.
If it is not, then write <tr><td>Additional notes:
<b><%=(Recordset1.Fields.Item("notes").Value)%></b></td> </tr>

However, the words "Additional notes:" keeps showing up on every page,
regardless of whether "notes" is empty or not.

What am I doing wrong?

thanks in advance, crispy

Jul 19 '05 #2
On Wed, 25 Feb 2004 22:07:22 -0500, crispy <unknown> wrote:
<%if (Recordset1.Fields.Item("notes").Value)="" then%>
<%else%>
<tr><td>Additional notes:
<b><%=(Recordset1.Fields.Item("notes").Value)%></b></td> </tr>
<%end if %>

However, the words "Additional notes:" keeps showing up on every page,
regardless of whether "notes" is empty or not.


Recordset1.Fields.Item("notes").Value contains a value that is not blank
but doesn't print on the page -- like NULL. Use Trim() to make sure the
value doesn't contain a space, and IsNull() to check for a null value, in
addition.
Jenny
Jul 19 '05 #3
crispy wrote:
I am sorry about posting such an elementary question, but I just can't
get this to work:

<%if (Recordset1.Fields.Item("notes").Value) ="" then%>


If the field contains a Null, then this comparison will return False. Better
is to use the Len() function:

if len(Recordset1.Fields.Item("notes").Value) = 0 then

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #4
I have found that not to be the case Bob. Sometimes can't remember now but
I think I got a Type Mismatch error or something.

I always use this now....

Dim stNotes

stNotes = objRs.Fields("Notes").Value
If Not IsNull(stNotes) Then
Response.Write Replace(Server.HTMLEncode(stNotes), vbCrLf, "<br>")
End If


"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
crispy wrote:
I am sorry about posting such an elementary question, but I just can't
get this to work:

<%if (Recordset1.Fields.Item("notes").Value) ="" then%>
If the field contains a Null, then this comparison will return False.

Better is to use the Len() function:

if len(Recordset1.Fields.Item("notes").Value) = 0 then

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 19 '05 #5
David Morgan wrote:
I have found that not to be the case Bob. Sometimes can't remember
now but I think I got a Type Mismatch error or something.

Really? I've been using this technique for years and never gotten a Type
Mismatch.

There used to be a kludge in the old VB days of appending an empty string to
the data to counteract the Null possibility, like this:
stNotes = objRs.Fields("Notes").Value & ""
Id sNotes = "" then

But I have not had to use that kludge for years.
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #6
"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message news:eS**************@TK2MSFTNGP12.phx.gbl...
David Morgan wrote:
I have found that not to be the case Bob. Sometimes can't remember
now but I think I got a Type Mismatch error or something.
Really? I've been using this technique for years and never gotten a Type
Mismatch.

There used to be a kludge in the old VB days of appending an empty string to
the data to counteract the Null possibility, like this:
stNotes = objRs.Fields("Notes").Value & ""
If sNotes = "" then

But I have not had to use that kludge for years.


That really isn't a kludge in VB. Since a string data type cannot hold a null, you either have to append a "" or do a test like

sNotes = IIF(IsNull(objRs.Fields("Notes").Value),"",objRs.F ields("Notes").Value)

The other option is to Dim sNotes as a Variant. You still get into trouble if you assign sNote to a TextBox Text Property.

Since all variables are Variants in VBScript, it is not necessary since Null can be stored in a Variant.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 19 '05 #7
Yes - but his original mail said he's always getting 'Additional notes'
showing up therefore:

<%
if not IsNull(Recordset1("notes")) then
%>
<tr><td>Additional notes:
<b><%=(Recordset1("notes"))%></b></td> </tr>
<%end if %>

is all he wants.

Martin

"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
crispy wrote:
I am sorry about posting such an elementary question, but I just can't
get this to work:

<%if (Recordset1.Fields.Item("notes").Value) ="" then%>
If the field contains a Null, then this comparison will return False.

Better is to use the Len() function:

if len(Recordset1.Fields.Item("notes").Value) = 0 then

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 19 '05 #8
What I've done before to deal with potentially null values is:

stNotes = objRS.Fields.Item("Notes").Value & ""

Ray at work

"David Morgan" <da***@davidmorgan.me.uk> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have found that not to be the case Bob. Sometimes can't remember now but I think I got a Type Mismatch error or something.

I always use this now....

Dim stNotes

stNotes = objRs.Fields("Notes").Value
If Not IsNull(stNotes) Then
Response.Write Replace(Server.HTMLEncode(stNotes), vbCrLf, "<br>")
End If


"Bob Barrows" <re******@NOyahoo.SPAMcom> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
crispy wrote:
I am sorry about posting such an elementary question, but I just can't
get this to work:

<%if (Recordset1.Fields.Item("notes").Value) ="" then%>


If the field contains a Null, then this comparison will return False.

Better
is to use the Len() function:

if len(Recordset1.Fields.Item("notes").Value) = 0 then

HTH,
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Jul 19 '05 #9
Thank you so much for your help everyone. crispy
On Thu, 26 Feb 2004 05:53:07 -0500, "Bob Barrows"
<re******@NOyahoo.SPAMcom> wrote:
crispy wrote:
I am sorry about posting such an elementary question, but I just can't
get this to work:

<%if (Recordset1.Fields.Item("notes").Value) ="" then%>


If the field contains a Null, then this comparison will return False. Better
is to use the Len() function:

if len(Recordset1.Fields.Item("notes").Value) = 0 then

HTH,
Bob Barrows


Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by D E | last post: by
reply views Thread by Thomas Guignard | last post: by
2 posts views Thread by Grant Stanley | last post: by
13 posts views Thread by eman1000@gmail.com | last post: by
28 posts views Thread by Steven Bethard | last post: by
10 posts views Thread by Luigi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.