Results 1 to 12 of 12

Thread: [RESOLVED] Invalid use of Null

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Resolved [RESOLVED] Invalid use of Null

    I get the error Saying
    "Invalid Use of Null"

    My code for Checking Null value is

    VB Code:
    1. IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage, "'", "")))

    Is something wrong in the code...

    Thanks

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Invalid use of Null

    VB Code:
    1. IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage), "'", ""))

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: Invalid use of Null

    Hi Shakti,

    Quote Originally Posted by shakti5385
    VB Code:
    1. 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

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Invalid use of Null

    Replace() function must be in the same format you had it in post #1:
    VB Code:
    1. Replace[COLOR=Red]([/COLOR][I][expression][/I], [I][find][/I], [I][replace][/I][COLOR=Red])[/COLOR]

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: Invalid use of Null

    Is this code wrong ??

    VB Code:
    1. IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage, "'", "")))

    Or am i missing out something...

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    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:
    1. Dim a As String
    2.    a = IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage, "'", "")))

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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:
    1. Dim a As String
    2.  
    3. a = Trim$(Replace(rs!replyMessage & "", "'", vbNullString))

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: Invalid use of Null

    Tried using
    VB Code:
    1. Dim a As String
    2.    a = IIf(IsNull(rs!replyMessage), "", Trim(Replace(rs!replyMessage, "'", "")))

    still the same error

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    Re: Invalid use of Null

    Quote 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:
    1. Dim a As String
    2.  
    3. a = Trim$(Replace(rs!replyMessage & "", "'", vbNullString))
    Hi Bush,
    Does this check for Null values ??

  10. #10
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Invalid use of Null

    try this
    VB Code:
    1. 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.


  11. #11
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Invalid use of Null

    Quote Originally Posted by Kuamr
    Hi Bush,
    Does this check for Null values ??
    if it's null it'll return ""

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Posts
    256

    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
  •  



Click Here to Expand Forum to Full Width