How do you replace a $ with a line break in a memo field?

Lee Attlesey

New Member
Joined
May 20, 2002
Messages
22
Hi all

I'm attempting to merge a number of excel columns into one to import into a new MS Access 97 db as a memo field.

I'm copying the colomns into word, converting the table into text seperated by a $ sign, this can then be appended into a memo field.

The part I'm stuck on is then replacing the $ with a line break... can this be done?

Reagrds,
Lee
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Re: How do you replace a $ with a line break in a memo field

You'll need to run an Access VBA routine. I wrote this in XP, using DAO so it's compatible with Access 97 and up:

Sub TestReplace()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim MyStr As String

Code:
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("Conversion Errors")
With rst
    .MoveFirst
    Do Until .EOF
        .Edit
        MyStr = Replace(![Error Description], "$", Chr(10))
        ![Error Description] = MyStr
        .Update
        .MoveNext
    Loop
End With
Set rst = Nothing
End Sub
Make the following changes to the code so it works in your system:
"Conversion Errors" to "My Table Name"
[Error Description] to [Field containing the text to replace]

Note: Chr(10) is the linefeed character. This routine does do replacements. However, the result is a field with the $ symbols replaced with the "I can't print this" square. No line feeds. Anybody got any ideas?

Denis
 
Upvote 0
Re: How do you replace a $ with a line break in a memo field

What if you imported the database, then walked the recordset using your own custom replace that inserts vbCrLf?

Hmmm, just tested. Doesn't seem to work. Just ends up truncating the field value at the replacement point.
 
Upvote 0
Re: How do you replace a $ with a line break in a memo field

Looking at mdmilner's response, I realised that Windows doesn't like Chr(10) or vbLf (the standard line feed). This does work:

In the code above, replace Chr(10) with vbCrLf

That gave the result you want, on my test example.
Denis
 
Upvote 0

Forum statistics

Threads
1,221,607
Messages
6,160,792
Members
451,671
Latest member
kkeller10

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top