[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Invalid use of Null Replace

Posted on 2006-05-10
5
Medium Priority
?
253 Views
Last Modified: 2010-04-25
Hello Experts,
I have a results page where I want to display memo fields with the original formatting, (Line spacing)
The code below works OK until it comes to an empty field.
<%
'replace spaces and put breaks
strText = (rsUpdate.Fields.Item("SkillsRequired").Value)
strText = replace(strText,VbCrLf,"<br>")
response.write strText
%>

Then I get this error.
Invalid use of Null: 'Replace'
/britishconsultancy/Assign-COMPLETED/print.asp, line 755
Can anyone tell me what code to use to avoid the error please.
Thanks
John
0
Comment
Question by:johnhardy
  • 3
  • 2
5 Comments
 

Author Comment

by:johnhardy
ID: 16647596
I think I have found the answer with the following small ammendment.
I hope it helps someone else
Thanks
John

<%
'replace spaces and put breaks
strText = (rsUpdate.Fields.Item("PurposeNonProfit").Value)
strText = replace("" & strText,VbCrLf,"<br>")
response.write strText
%>
0
 
LVL 25

Accepted Solution

by:
Rouchie earned 1400 total points
ID: 16649565
You cannot do a replace on a NULL value, that's why you get the error.  You should check for NULL or an empty string before replacing;

<%
IF NOT IsDbNull(rsUpdate.Fields.Item("PurposeNonProfit").Value) AND rsUpdate.Fields.Item("PurposeNonProfit").Value <> "" THEN
  response.write(replace(rsUpdate.Fields.Item("PurposeNonProfit").Value,VbCrLf,"<br/>"))
ELSE
  response.write("")
END IF
%>
0
 

Author Comment

by:johnhardy
ID: 16649973
Thanks Rochie for that information.
The code I altered above does seem to be working OK with empty fields.
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 16650088
Yes, I just included that little snippet for general reference if anyone else needs help.  Your method is simply forcing the NULL to be converted to text by adding a blank string to it.  I'm not too sure how reliable that would be should it need expanding further - but at least it works for you!
0
 

Author Comment

by:johnhardy
ID: 16652072
Thanks its away great to have the best advice
Regards
John
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question