Results 1 to 3 of 3

Thread: Weird replace error (SOLVED)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2004
    Location
    Earth 4 now.
    Posts
    27

    Weird replace error (SOLVED)

    I have a Access database with field type=Memo.

    When I show this field in the browser I use this:

    <%
    descr = rsVisitReport("Address")
    descr = replace(descr, vbCrlf, "<BR>")
    Response.Write descr
    %>
    This works fine with fields that contain data but it returns an error when the Address field is empty.

    Microsoft VBScript runtime error '800a005e'

    Invalid use of Null: 'replace'

    /system/Page.asp, line (number)



    So I tried this little code:
    <%
    if (not rsVisitReport("Address")="") then
    descr = rsVisitReport("Address")
    descr = replace(descr, vbCrlf, "<BR>")
    Response.Write descr
    end if
    %>
    This fixes the old problem and empty fileds are shown correctly but when the field isn't empty and the replace takes place, now give the error:

    Microsoft VBScript runtime error '800a005e'

    Invalid use of Null: 'replace'

    /system/Page.asp, line (number)



    I don't get it.
    Last edited by ShotokanTuning; Jul 15th, 2004 at 04:47 AM.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Nulls - always crap.

    Couple of ways to fix:

    1) strData = rst("field") & ""
    2) strData = nnz(rst("field"),"") - where nnz is a function to replace the nnull value with a default value
    3) If not (Isnull(rst("field"))) then 'do code to process/replace


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2004
    Location
    Earth 4 now.
    Posts
    27
    Method 3 is the same as I used. Also same result.

    Method 1 works perfectly.

    Thanks again.

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