Avatar of error_prone
error_prone
 asked on

String Extraction Memo Field

Is there a way to get the first 2 lines of a memo field?  The lines would be split by a hard return.
Microsoft Access

Avatar of undefined
Last Comment
Patrick Matthews

8/22/2022 - Mon
danishani

Try to use the InStr() function together with Chr(13), something like:

InStr(1,[YourMemoField], Chr(13))

HTH,
Daniel
error_prone

ASKER
This just gives me a number and not the string on the first and second lines.
Hamed Nasr

Try this: memo field: rt

Private Sub Command8_Click()
    Dim s As String   ' string to hold memo text
    s = Me.rt 'memo field
    Dim x As Variant ' array to hold lines of text
    x = Split(s, Chr(13) & Chr(10))
    Dim l1 As String  'line 1
    Dim l2 As String
    l1 = Replace(x(0), Chr(13) & Chr(10), "")
    l2 = Replace(x(1), Chr(13) & Chr(10), "")
End Sub
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Patrick Matthews

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
error_prone

ASKER
Actually need to use it in a query...
Hamed Nasr

play with chr(10) and see the effect on the second line.
Patrick Matthews

hnasr,

Your apporach will throw an error if there is only one line in the memo column.

:)

Patrick
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
error_prone

ASKER
matthewspatrick - That works!
Patrick Matthews

error_prone,

Glad to help!  If you have not already done so, I would really appreciate it if you could please return to my article
https://www.experts-exchange.com/Programming/Languages/Visual_Basic/A_1336-Using-Regular-Expressions-in-Visual-Basic-for-Applications-and-Visual-Basic-6.html
and click 'Yes' for the 'Was this helpful?' voting.

Patrick