Results 1 to 7 of 7
  1. #1
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338

    Replace Function returing #Error


    Hello-

    I'm using this code CPT2new: Replace(Replace(Replace(Replace([CPT2],"+",""),"/",""),".",""),"*","") to remove characters.
    When the fields are empty it returns #Error.

    How can i get it to stop returning #Error?
    If it's empty than i want it to return it empty.


    Thank you

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Not tested, but maybe use IIF()
    Code:
    CPT2new: IIF(Len(Trim([CPT2]))=0,"", Replace(Replace(Replace(Replace([CPT2],"+",""),"/",""),".",""),"*",""))
    Last edited by ssanfu; 08-27-2014 at 11:58 AM. Reason: computer can't spell

  3. #3
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    Steve

    I try it but still getting #Error



    Quote Originally Posted by ssanfu View Post
    Not tested, but maybe use IIF()
    Code:
    CPT2new: IIF(Len(Trim([CPT2]))=0,"", Replace(Replace(Replace(Replace([CPT2],"+",""),"/",""),".",""),"*",""))

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    This works:
    Code:
    CPT2new: Replace(Replace(Replace(Replace(NZ([CPT2],""),"+",""),"/",""),".",""),"*","")

  5. #5
    Ray67 is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    338
    Thank you very much Joe
    Worked Great!!!!!!!!!!!!!!



    Quote Originally Posted by JoeM View Post
    This works:
    Code:
    CPT2new: Replace(Replace(Replace(Replace(NZ([CPT2],""),"+",""),"/",""),".",""),"*","")

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Your welcome!

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Well, I learned something...

    I have used (in A2000)
    [code[Len(Trim([FieldOrControlName]))=0 [/code]

    to determine if it is non-null and non-space(s) because just using NZ() was allowing some records to be calculated when they shouldn't be.

    Apparently A2010, won't allow just spaces to be entered into a field.

    In the query, even using
    Code:
    CPT2newLT: Len(Trim([CPT2]))=0
    where CPT2 is NULL, doesn't result in TRUE, it returns NULL.

    Trying
    Code:
    CPT2newL: Len([CPT2])
    when CPT2 is NULL, returns NULL, not 0...

    It looks like I have a lot of code to review...


    BTW, in testing I found this also works:
    Code:
    CPT2new: Replace(Replace(Replace(Replace([CPT2] & "","+",""),"/",""),".",""),"*","")

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Using a wildcard with the replace function
    By razkowski in forum Queries
    Replies: 6
    Last Post: 08-12-2014, 08:13 AM
  2. Replace Function
    By thescottsman92 in forum Access
    Replies: 5
    Last Post: 09-02-2013, 01:25 AM
  3. Help with Replace Function...
    By redbull in forum Programming
    Replies: 5
    Last Post: 06-27-2013, 04:05 PM
  4. Error with Replace Function
    By Juan4412 in forum Queries
    Replies: 1
    Last Post: 09-30-2012, 05:48 PM
  5. Replies: 3
    Last Post: 06-07-2012, 07:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums