Results 1 to 11 of 11
  1. #1
    timmygrover is offline Novice
    Windows Vista Access 2003
    Join Date
    Dec 2011
    Posts
    26

    Replace function adding in unwanted carriage return

    So I'm using the replace function to automatically format html,



    here's my code

    Replace([thethingthati'mreplacing], Chr(13), "</dd>" & Chr(13) & Chr(9) & Chr(9) & "<dd>")

    It works like a charm except that for some reason the Replace function throws in a carriage return at the end of each replace. The code still works fine with the return, but my formatting OCD is kicking in and I MUST solve this or die trying.

    Does anyone know how to negate the return? Tried adding in a chr code for DEL, but that didn't work.

    Thanks in advance for any help!

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    Here's the syntax
    http://www.techonthenet.com/access/f...ng/replace.php

    What do you have and what is the result of the Replace?

  3. #3
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    timmy, give me a sample input you got and a sample output you want.

  4. #4
    timmygrover is offline Novice
    Windows Vista Access 2003
    Join Date
    Dec 2011
    Posts
    26
    I want to put in:

    thing one
    thing two
    thing three

    and get out

    <dd>thing one</dd>
    <dd>thing two</dd>
    <dd>thing three</dd>

    Instead, I get this:

    <dd>
    Thing One</dd>
    <dd>
    Thing Two</dd>
    <dd>
    Thing Three</dd>

    The replace function is adding in a carriage return after the end of the function. I've tried adding in a del character to see if that works, and I've tried a nested statement where it first does the replacement I outlined above and then replaces the return with a null string, but neither of those things have worked.

  5. #5
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    what's the source of the input? a file? you, manually typing in text? a table?

    it's very possible that you're running into an issue with visual basic here is known by some, not by others. bottom line, try everything you can to get out sample returns.

    here are some things to try, and knowledge if you don't already have it:

    IN VB6/VBA:

    chr(9) = TAB
    chr(13) = carriage return
    chr(10) = line feed

    so what you're now telling vb is to replace CR's with your preferred string. but what is your target is not a CR? 1st, try replacing it with chr(10).

    in vb6/vba, all of these different programming statements mean almost the same thing, and should, if MS had any brains at all, be rolled into one statement.

    chr(9)
    vbTab (enum val in vb6)
    chr(13)
    vbCr (enum val in vb6)
    chr(10)
    vbLf (enum val in vb6)
    vbCrLf (enum val in vb6)

    try an "all-possibilities" approach using that information and see if things don't just work out great for ya. I hope it does! also keep in mind that the whitespace associated with the tab ascii value is not a fit-all approach. it does not translate from program to program perfectly, as it really shouldn't anyway! (unless I've already gone out of my mind today again? )

    if this stuff doesn't work, post back.

  6. #6
    help_me_with_access is offline help_me_with_excel
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    262
    OH, by the way, all of that information I just gave you is not even consistent in usage between the access interface and it's visual basic IDE counterpart! so that leaves you with trial and error until you figure out what works.

    sorry...

  7. #7
    timmygrover is offline Novice
    Windows Vista Access 2003
    Join Date
    Dec 2011
    Posts
    26
    Alright, so I added chr(10) into the mix, no change. I'm still getting one line break that i didn't ask for. My goal is to take text that looks like this:

    thing1
    thing2
    thing3

    and then to take each line break and replace it with: </dd>, and then a line break, two chr(9), and a <dd>. I get everything I ask for, PLUS one extra return. Thanks for the suggestions so far, still no solution though!

  8. #8
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Try this

    Code:
    Replace([thethingthati'mreplacing], Chr(13), "</dd>" & Chr(9) & Chr(9) & "<dd>")

  9. #9
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Never mind misread it.

  10. #10
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    It might help if you include a little more detail. Is this in code or a query? If in code is it a subroutine or Function what are the previous and following lines doing? What you've stated essentialy says take a carriage return and replace it with "</dd> carriage return tab tab <dd>" to give you good advice we need to understand more of the context of what you're trying to do. Otherwise it's easy to mis-read and get bad information.

  11. #11
    timmygrover is offline Novice
    Windows Vista Access 2003
    Join Date
    Dec 2011
    Posts
    26
    I'm using the code in an unbound text field in a form. The idea is that you'll paste stuff into one field and then this text box will automatically format the text to save time.

    Here is the complete string:

    =IIF(IsNull([BSDD1-1]),Null,Chr(9) & Chr(9) & "<dd>" & Replace([BSDD1-1],Chr(10),"</dd>" & Chr(10) & Chr(9) & Chr(9) & "<dd>") & "</dd>" & Chr(13))

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

Similar Threads

  1. Replies: 3
    Last Post: 06-07-2012, 07:05 AM
  2. Replies: 1
    Last Post: 02-08-2012, 04:44 PM
  3. Replace Carriage Returns with Spaces
    By chitan in forum Queries
    Replies: 1
    Last Post: 12-15-2011, 11:14 AM
  4. Carriage return in a CSV file
    By btidwell3 in forum Import/Export Data
    Replies: 1
    Last Post: 09-09-2011, 05:19 PM
  5. How to force carriage return between strings?
    By Divardo in forum Reports
    Replies: 1
    Last Post: 05-21-2009, 10:50 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