|
-
Dec 22nd, 2006, 02:34 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Invalid use of Null
I get the error Saying
"Invalid Use of Null"
My code for Checking Null value is
VB Code:
IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage, "'", "")))
Is something wrong in the code...
Thanks
-
Dec 22nd, 2006, 02:40 AM
#2
Re: Invalid use of Null
VB Code:
IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage), "'", ""))
-
Dec 22nd, 2006, 02:50 AM
#3
Thread Starter
Hyperactive Member
Re: Invalid use of Null
Hi Shakti,
 Originally Posted by shakti5385
VB Code:
IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage), "'", ""))
if a remove the last bracket i.e ")" it gives a complie error saying
"argumetn not optional "
and the replace function is higlighted
-
Dec 22nd, 2006, 02:58 AM
#4
Re: Invalid use of Null
Replace() function must be in the same format you had it in post #1:
VB Code:
Replace[COLOR=Red]([/COLOR][I][expression][/I], [I][find][/I], [I][replace][/I][COLOR=Red])[/COLOR]
-
Dec 22nd, 2006, 03:00 AM
#5
Thread Starter
Hyperactive Member
Re: Invalid use of Null
Is this code wrong ??
VB Code:
IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage, "'", "")))
Or am i missing out something...
-
Dec 22nd, 2006, 03:21 AM
#6
Re: Invalid use of Null
IIF always Returns 2nd or 3rd parameter, depending on the condition in the first parameter, if this condition is True it returns 2nd parameter, else it returns 3rd parameter. But here you are not using the returned string, thats the error. Do something like:
VB Code:
Dim a As String
a = IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage, "'", "")))
-
Dec 22nd, 2006, 04:53 AM
#7
Re: Invalid use of Null
aside from the need as assign the value as jcis pointed out - the error is because both the second and third conditions are evaluated, regardless of the first - so if rs!replyMessage is indeed Null, VB still attempts to do the replace, and you get the error.
You shouldn't use the IIf construct, it's really slow (and in this case not need), the following would suffice:
VB Code:
Dim a As String
a = Trim$(Replace(rs!replyMessage & "", "'", vbNullString))
-
Dec 22nd, 2006, 04:55 AM
#8
Thread Starter
Hyperactive Member
Re: Invalid use of Null
Tried using
VB Code:
Dim a As String
a = IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage, "'", "")))
still the same error
-
Dec 22nd, 2006, 04:56 AM
#9
Thread Starter
Hyperactive Member
Re: Invalid use of Null
 Originally Posted by bushmobile
You shouldn't use the IIf construct, it's really slow (and in this case not need), the following would suffice:
VB Code:
Dim a As String
a = Trim$(Replace(rs!replyMessage & "", "'", vbNullString))
Hi Bush,
Does this check for Null values ??
-
Dec 22nd, 2006, 04:58 AM
#10
Re: Invalid use of Null
try this
VB Code:
IIf(IsNull(rs!replyMessage), "", Trim(Replace((rs!replyMessage & ""), "'", "")))
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Dec 22nd, 2006, 04:59 AM
#11
Re: Invalid use of Null
 Originally Posted by Kuamr
Hi Bush,
Does this check for Null values ??
if it's null it'll return ""
-
Dec 22nd, 2006, 05:41 AM
#12
Thread Starter
Hyperactive Member
Re: Invalid use of Null
Both Methods Work!!!
Thank you Bush
Thank You Ganesh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|