Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace carriage returns in a string with comma

Status
Not open for further replies.

Palmyra

Programmer
Jan 5, 2007
150
US
One of the fields in a table I've been given has multiple values separated by carriage returns. Can I used vb Replace to change those carriage returns to commas?

Thanks.
 
Yes, of course, you can use Replace in VBA - if you have the data in VBA but ...

... if what you're really asking is can you use Replace in SQL in Access then the answer is No - or not directly, so ...

... can you give a few more details of what you want to know?

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
The field has unreadable characters separating values. The unreadable character is an ascii 2 (or double quote).
I know the third character is always an ascii 2.

I open a recordset in vba. I want to replace the ascii2 with a pipe |

strSQL = "Select tsindex, tlindex, tbatch, trecbuffer from ewin_tlabel"
Set rs = DB.OpenResults(strSQL)

Dim txt As String
Dim fld As Integer

txt = rs.Value("trecbuffer")
fld = Asc(Mid$(txt, 3, 1))
If InStr(rs.Value("trecbuffer"), fld) > 0 Then
txt = Replace(txt, fld, "|")

End If

My syntax is off or something, because although fld does return the ascii2, my If..isn't returning anything.

Thanks.
 
You may try something like this:
txt = Replace(rs.Fields("trecbuffer"), Chr(2), "|")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks. I tried below and got 'Error 438, Object doesn't support this property or method'

strSQL = "Select tsindex, tlindex, tbatch, trecbuffer from ewin_tlabel " & _
"order by tsindex asc"

Set rs = DB.OpenResults(strSQL)

Dim txt As String
Dim fld As Integer

txt = rs.Value("trecbuffer")

txt = Replace(rs.Fields("trecbuffer"), Chr(2), "|")
rs.MoveNext

End Sub
 
Sorry for the typos:
Set rs = DB.OpenResults(strSQL)
Dim txt As String
txt = Replace(rs.Value("trecbuffer"), Chr(2), "|")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Run-time error 94 - 'Invalid use of null'.

I know txt is populated.
 
I know txt is populated
How do you know that ?
Furthermore, what do you want if the SQL returns many rows ?

BTW, what is DB ? (I don't know which object exposes an OpenResults method returning a Recordset ...)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top