|
 |
access_asp thread: if statement not working!
Message #1 by jake williamson 28 <jake.williamson@2...> on Tue, 11 Jun 2002 11:55:03 +0100
|
|
hi,
i've got a database with stockists in it. some have url's and emails, some
dont. the one's that dont have no entry and show a Null value.
i would like to say:
Website: www.clickhere.com
and
Email: thename@d...
but obviously dont want just the words "Website: " and "Email: " showing if
the result is null...
so i wrote this if statement:
<%
If postcodeResults.Fields.Item("CONTACT") = "Null" Then
Response.Write ""
Else
Response.Write "Contact Name: " &
postcodeResults.Fields.Item("CONTACT").Value & ""
End If
%>
the same for the url.
but it dont work!! it still prints the words "Website: " and "Email: " but
with no value!!
what i miss????!!
cheers,
jake
Message #2 by paul@f... on Tue, 11 Jun 2002 19:08:47
|
|
Jake,
The line that reads postcodeResults.Fields.Item("CONTACT") = "Null" is
most likely where the problem is.
By putting Null in quotation marks ie "Null" the comparison is checking
for a text string "Null". I think what might work would be:
If IsNull(postcodeResults.Fields.Item("CONTACT")) Then .....
I hope this helps.
Paul McKeever.
Message #3 by "Ken Schaefer" <ken@a...> on Wed, 12 Jun 2002 16:43:59 +1000
|
|
In addition to Paul's advice, I'd sugges this is another place where IIF()
can be used:
SELECT
IIF(IsNull(Contact), " ", Contact)
will return either the value in the Contact field (if Contact is not NULL),
or a string if Contact is NULL. Then you don't need the extra
conditional code in your ASP page.
Lastly, have you ever heard of .GetRows - fantastic little method that'll
really help you scale your Access Application:
If not objRS.EOF then
arrResults = objRS.GetRows
End If
' Now dispose of objRS
' Because results are in the array arrResults
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <paul@f...>
Subject: [access_asp] Re: if statement not working!
: Jake,
:
: The line that reads postcodeResults.Fields.Item("CONTACT") = "Null" is
: most likely where the problem is.
:
: By putting Null in quotation marks ie "Null" the comparison is checking
: for a text string "Null". I think what might work would be:
:
: If IsNull(postcodeResults.Fields.Item("CONTACT")) Then .....
:
: I hope this helps.
:
:
: Paul McKeever.
Message #4 by jake williamson 28 <jake.williamson@2...> on Wed, 12 Jun 2002 12:35:01 +0100
|
|
got it! makes sense and will help out a lot in other areas.
here's the complete if statement
<%
If IsNull(countyResults.Fields.Item("CONTACT")) Then
Response.Write "There is no contact"
Else
Response.Write "Contact: " +
countyResults.Fields.Item("CONTACT").Value + ""
End If
%>
thanks for the help, as always appreciated,
jake
|
|
 |