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

Parsing a memofield

Status
Not open for further replies.

GrantB80

Programmer
Jan 4, 2001
4
AU
Hello,

I need to parse a memofield, though I have no idea of how to go about this. If anyone has any ideas or could point me to some information, it would help me a lot.

Thanx,
Grant
 
You parse a memo field the same way you parse a text field or any other string value. Basically, you use the following string functions:
Left$(), Mid$(), Right$()
Instr() (and maybe InstrRev in Access 2000)
Len()
Trim$(), LTrim$(), and RTrim$()

For more specific information, you'll have to be more specific about what you want to extract. If all you want to do is break it into words, that would be very different from finding specific information based on the surrounding text or delimiters.
 
I intend to search a memofield for symbols such as @b, @i, @u, ##.

The symbols are used to depicted what words will be bold(@b) italics(@i) and underlined(@u). The ## tells me where to insert particular text from another table.

Do you know how to parse these and the add the information to a report?

I tried converting the information to the richtext format and using richtext control on a report though when printed it would not print out the first letter of each line of the text.

Thanx, for those functions - I will attempt to parse the information, using them.


Grant.
 
Here's how you find and insert the replacement text for the ## token. You can use a similar method for the formatting tokens.

I'm going to start with the following assumptions:
1. Me!rtxText is a RichText control containing the data from the memo field. It could just as well be an ordinary text box or a string variable, for this example.
2. You want to replace the ## token with the text in a variable named strDepartment.
Code:
    Dim i As Integer
    i = InStr(Me!rtxText, "##")
    If i <> 0 Then
        Me!rtxText = Left$(Me!rtxText, i - 1) &amp; strDepartment &amp; Mid$(Me!rtxText, i + 2)
    End If
The InStr() function sets i to the first occurrence of &quot;##&quot; in the data. i will either be 0, if &quot;##&quot; isn't found, or will be the index of the first &quot;#&quot;, with 1 being the first character, etc.
The assignment statement then constructs a string consisting of the leftmost i-1 characters (i.e., the part of the string that precedes &quot;##&quot;), the replacement text, and the right end of the string starting at the i+2 position. We use i+2 because i is the index of the first &quot;#&quot;, and we want to extract the part of the string starting two characters to the right of it. This is a special use of the Mid$() function. Normally, you specify as arguments the string, the starting character index, and the length you want Mid$() to extract. But if you don't specify any length, Mid$() extracts all the characters to the end of the string.

If you just wanted to remove the &quot;##&quot; token, you would use the expression:
Code:
    Left$(rtxText, i - 1) &amp; Mid$(rtxText, i + 2)
I don't know what you plan to do with @b, @i, and @u. If you need to replace them with something, the same technique will work. If you instead need to use their positions in setting up RichText formatting, remember that you'll have to remove them, and when you do all the remaining text will shift left by 2 positions. So for each formatting token, the index of the text that follows it changes by -2.

Hope this helps.
Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top