VBA code to replace chr10 and chr13 to space

reedhillltd

New member
Local time
Today, 18:29
Joined
Jun 20, 2014
Messages
6
Hello I'm working on an eBay uploader access program for Ebay's File Manager

Our description contains line feeds and carriage returns. I have very little knowledge of Vba, and I can t find any tutorials on how to replace the characters with spaces on how to program this.

The table is called tblCustomer
The field is called *Description

Thank you in advance

I'm using access 2007
 
Run a query

Code:
UPDATE tblCustomer Set description = Replace(description, Chr(13), " ")

Something like that
 
thankyou for the reply

in need to replace both chr10 and chr13 at the same time

is there any way to run two replace functions within one field
 
is there any way I can make a button in my form that when clicked will run both queries automatically
 
Try that out. lol
Code:
UPDATE tblCustomer 
	Set description = 
                IIF(
			InStr(1, description, Chr(13),
			Replace(description, Chr(13), " "),
			IIF(
				InStr(1, description, Chr(10)),
				Replace(description, Chr(10), " "),
				description
                           )
 		   )
 
This is all air code, so let me know if you get any errors. :)
Code:
Private Sub btnButton_Click()
    CurrentDb.Execute "UPDATE tblCustomer " & _
                            "Set description = " & _
                                "IIF(" & _
                                    "InStr(1, description, Chr(13)) > 0," & _
                                    "Replace(description, Chr(13), "" "")," & _
                                    "IIF(" & _
                                            "InStr(1, description, Chr(10)) > 0," & _
                                            "Replace(description, Chr(10), "" "")," & _
                                            "Description" & _
                                        ")" & _
                                ")"
End Sub
 
Why so many InStr? You only need.
Code:
UPDATE tblCustomer SET description = Replace(Replace(description, Chr(10), ' '), Chr(13), ' ')
Give the above Query a name (say replaceQry), then use in the button code.
Code:
Private Sub buttonName_Click()
    CurrentDB.Execute "replaceQry"
End sub
 

Users who are viewing this thread

Back
Top Bottom