Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4673
  • Last Modified:

Microsoft VBScript runtime error '800a005e' - Invalid use of Null: 'replace'

Hi All,

Getting the following error:

Microsoft VBScript runtime error '800a005e'
Invalid use of Null: 'replace'
/web/checkout5.asp, line 241

On this page, i'm opening a recordset....

set rs=openrs("SELECT * FROM affildesc WHERE affiliateid=" & id)
description=rs("description")
terms=rs("terms")
closers()

then sending an email with the values....

  if confemail="ON" and emailcomp<>"None" then
  emailto=email
  emailtoname=name
  emailfrom=email_2
  emailfromname=clerkname
  emailsubject=emailsubject1
  emailbody=emailbody1
  emailbody=replace(emailbody, "##DESC##", description)
  emailbody=replace(emailbody, "##TERMS##", terms)
  call sendemail()
  end if

Error on Line 241 - emailbody=replace(emailbody, "##TERMS##", terms)

Field terms is NULL when i look at it in SQL Server,
1. how do i write the code here to get it to work
2. Have i designed my database (SQL Server) incorrect by allowing NULLs ?
0
fgict
Asked:
fgict
  • 4
  • 3
  • 2
  • +2
1 Solution
 
hongjunCommented:
if you don't want the errors you can do something like this

emailbody=replace(emailbody, "##TERMS##", "" & terms)


hongjun
0
 
sforcierCommented:
To answer your second question, based on what this snippet seems to be doing, you probably want to have SQL Server not allow null values. If you have a design requirement (for the application) that each affiliate *must* have their own terms, then you should not allow nulls in the database.

If one or more affiliates may have blank terms then you could consider allowing nulls, but even in this case, I wouldn't do it. In the case where blank terms are allowed I would disallow null and set the default value to an empty string. As you can tell, processing an empty string in your ASP will raise fewer issues when it comes to processing strings and it will saves you a few steps over having to check for a null value in certain situations.

Hope this helps,
Sid
0
 
nurbekCommented:
check the emailbody variable

Response.Write(emailbody)
it maybe NULL or blank
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
thefritterfatboyCommented:
As nurbek says - this error is from a variable being Null.

Check the variables for nulls before calling replace by using ISNULL(variable)

Do not use hongjun's idea. This will append a null to a string making it a double null-terminated string. Appending anything at a later part of your script will fail as VBScript will terminate the string at the null.
0
 
thefritterfatboyCommented:
if not isnull(emailbody) then
  emailbody=replace(emailbody, "##DESC##", description)
  emailbody=replace(emailbody, "##TERMS##", terms)
else
  emailbody = ""
end if
0
 
illCommented:
'instead of
set rs=openrs("SELECT * FROM affildesc WHERE affiliateid=" & id)
description=rs("description")
terms=rs("terms")

' try this. the rest of code stays.
set rs=openrs("SELECT * FROM affildesc WHERE affiliateid=" & id)
description=""
terms=""
if not isnull( rs("description") ) then
  description=rs("description")
end if
if not isnull( rs("terms") ) then
  terms=rs("terms")
end if
0
 
illCommented:
in generall it's better to get exact result directly from database than check it in VBScript. so if you need only these two fields and you're running mssql execute this query. and do not change anything else in asp.
-----------
set rs=openrs("SELECT ""description""=isnull(description,''),""terms""=isnull(terms,'') FROM affildesc WHERE affiliateid=" & id)
0
 
thefritterfatboyCommented:
Or use this SQL

"SELECT * FROM affildesc WHERE affiliateid=" & id & " AND description IS NOT NULL AND terms IS NOT NULL"
0
 
illCommented:
@thefritterfatboy
imo, your query is not correct.  you are removing recods from resultset. this fields are not "a must" according to question.
0
 
thefritterfatboyCommented:
I see no reason to send an email with no information, but that's my opinion.

Won't your SQL return "undeclared variable" errors unless you use

set rs=openrs("SELECT isnull(description,'') AS description, isnull(terms,'') AS terms FROM affildesc WHERE affiliateid=" & id)

??
0
 
nurbekCommented:
Error was

Error on Line 241 - emailbody=replace(emailbody, "##TERMS##", terms)

and solution is emailbody is NULL

and the fgict (the author)
should check emailbody values whether is NULL or not

as

thefritterfatboy wrote how to check and replace

:)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now