Link to home
Start Free TrialLog in
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.
Avatar of danishani
danishani
Flag of United States of America image

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

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

HTH,
Daniel
Avatar of error_prone
error_prone

ASKER

This just gives me a number and not the string on the first and second lines.
Avatar of 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
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Actually need to use it in a query...
play with chr(10) and see the effect on the second line.
hnasr,

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

:)

Patrick
matthewspatrick - That works!
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