473,221 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

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
9 1350
<%
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: D E | last post by:
Ok the subject line is basically the question. Obviously this won't work. What is the technical reason? Is it because here, "test1" is sort of like a static object now? What exactly is "test1"...
0
by: Thomas Guignard | last post by:
Hi Is it possible to re-use the content of a column that is just created in the SELECT statement? Here an example SELECT (complicated formula) AS result, name, surname,...
4
by: +Vice | last post by:
Can anyone help me translate this statement from using the legacy outer joins to the SQL-92 standards? Select CA.* From Customer C, Shipper S, Customer_Order CO, Cust_Address CA Where...
4
by: Tom Walker | last post by:
I cannot get the WHERE statement to work correctly unless I use a literal with the LIKE. I want to use a working storage data name so that I can vary the WHERE statement. Example that works: ...
2
by: Grant Stanley | last post by:
I'm writing a database client program in C#, and it accesses a MS SQL V7 database. In one part of my program I am using a SqlCommand class to run a SQL Statement, the command text uses parameters,...
4
by: Dave | last post by:
I have a field with data type of memo in my access database. I run a query from c# to access this field and it cuts off my string to only 255 characters. If i run this query directly in access...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
10
by: Luigi | last post by:
Hello all! I'm a newbie in PHP. I have written a short script that tries to update a SQLite database with the user data. It is pretty simple, something like this: <?php $sqlite =...
2
by: Phillip B Oldham | last post by:
What would be the optimal/pythonic way to subject an object to a number of tests (based on the object's attributes) and redirect program flow? Say I had the following: pets = {'name':...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.