Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Avoiding NULL content w/Access DB

Status
Not open for further replies.

jasonsalas

IS-IT--Management
Jun 20, 2001
480
GU
Hi all,

I'm working on a minor project and trying to have a script write an HTML non-breaking space (" ") if it reads across a column in a single DB record that doesn't have any data in it (NULL). The script is writing several column vertically on the page, separating each by a horizontal rule.

Here's the code I've been trying to use, but unsuccessfully so:

<%
If objRS(&quot;Brief1&quot;) <> &quot;&quot; Then
Response.Write(&quot;<DIV>&quot; & objRS(&quot;Name&quot;) & &quot;<hr></DIV>&quot;)
Else
Response.Write(&quot;&nbsp;&quot;)
End If
%>

The problem I'm getting is that regardless if the DB column has data in it or not, the script writes out the horizontal rule, making the page ugly. I've used this type of If...Then construct calling form data before, but not with a DB.

Any ideas? Thanks for your help!

JS
 
Hi

Try this

Code:
If objRS(&quot;Brief1&quot;)<>&quot;&quot;
and NOT isNull(objRS(&quot;brief1&quot;)
Code:
 then

That should upset that field's plan to wind you up. Derren
[The only person in the world to like Word]
 
Thanks...I tried your code and remembered the IsNull method...but no dice. All that does is prevent the content from being displayed. Any other ideas?
 
OK... Here's another get around

tempvar = objRS(&quot;Brief1&quot;)

Then test if tempvar is empty. I have found this to work well as it seems to convert a null into an &quot;&quot;
Derren
[The only person in the world to like Word]
 
Hi Derren,

Sorry...still no dice. I can't figure this out...it's displaying the horizontal line but not the content. Argh.

E-mail me at jason@kuam.com if you'd like and I'll send you the code.

Thanks for your help!
 
Jason,

Is the if...else working then?

Your actual HTML code may be causing the problems. When you view the HTML source in the browser do you see the
Code:
<DIV>database text<hr></DIV>
actually written in the page or is it not writing the code in the response? If it is writing the rule when there is content and the
Code:
nbsp
when the field is empty it can only be your html which is in error.

If you can, send the HTML response page to me at derren@kbase-connect.co.uk and I shall look at it as well.


Derren
[The only person in the world to like Word]
 
A-ha! I found what it is...I forgot (I've been doing so much ASP.NET work I've slipped a little in classic ASP) that you can only insert one refernce through the instantiated recordset once per page.

I had to do a looong workaround using an additional variable, using the following:

<%
B1 = objRS(&quot;Brief1&quot;)

If IsNull(B1) Then
Response.Write(&quot;&nbsp;&quot;)
Else
Response.Write(&quot;<DIV>&quot; & B1 & &quot;<hr></DIV>&quot;)
End If

%>

It's ugly, but it works. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top