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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid use of Null: 'Replace' error

Status
Not open for further replies.

shopwise

Technical User
Sep 22, 2008
52
US
why is the following code giving an Invalid use of Null: 'Replace' error even though I have placed in an if statement and even when the field is not null?

dim myVar
myVar = (products.Fields.Item("CustomMemo01").Value)
If myVar <> "" Then
dim script
dim note
dim texting
script=(products.Fields.Item("CustomMemo01").Value)
note=(Replace(script,":",":</td><td valign=top>"))
texting=(Replace(note,VBCrLf,"</td></tr><tr><td valign=top>"))
End If
 
Null is not the same thing as an empty string. Most of the time we like to treat them the same though. The easiest way to treat a NULL as an empty string is to concatenate an empty string, like this:

Code:
dim myVar
myVar = [!]"" & [/!]products.Fields.Item("CustomMemo01").Value
If myVar <> "" Then
  dim script
  dim note
  dim texting

  script= [!]"" & [/!]products.Fields.Item("CustomMemo01").Value
  note=(Replace(script,":",":</td><td valign=top>"))
  texting=(Replace(note,VBCrLf,"</td></tr><tr><td valign=top>"))
End If

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
The alternate way (to George's method)

Code:
if not isNull(myVar) and not isEmpty(myVar) and myVar <> "" then
' execute code if value is not null,empty or blank
end if

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top