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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Multi Line to Single Line

Status
Not open for further replies.

tristap

Technical User
Jun 24, 2005
16
0
0
AU
Can anyone advise if there is a way to import an MS Access table which has a multi line comment field into a single lined field ie. get rid of the carriage returns on import?
 
You can import it in the regular way and then apply an update query like:

UPDATE [MyTable] SET [MyTable].[MyField] = Replace(nz([MyTable].[MyField],""),Chr(13) & Chr(10),"");

You can also create a procedure that applies this transformation for any combination of Table & Field.

Code:
Sub RemoveCrLf(TableName, FieldName)
CurrentDb.Execute "UPDATE [" & TableName & "] SET [" & TableName & "].[" & FieldName & "] = Replace(nz([" & TableName & "].[" & FieldName & "],''),Chr(13) & Chr(10),'');"
End Sub
 
Can you please explain the above code and also why I would need to pass the table and field name to the procedure. Would I not just include it in the sql statement?
 
Added a button on a form to execute your code supplied and the below works:

Private Sub cmdReplaceText_Click()
Call RemoveCrLf("zz", "txtDescription")
End Sub

Sub RemoveCrLf(TableName, FieldName)
Dim mySQL As String
mySQL = "UPDATE [" & TableName & "] SET [" & TableName & "].[" & FieldName & "] = Replace(nz([" & TableName & "].[" & FieldName & "],''),Chr(13) & Chr(10),'');"
CurrentDb.Execute mySQL
End Sub

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top