Readin line after line of a memo field in VBA

G

Guest

I need to search for a specific string on each line in a memo field :

XXXAAAXXXXXXXXXXXXXXX
XXXXXXXXXXAAAXXXXXXXX
XXXXXXXXXXXXXXXXXXXXX

Searching "AAA" would return True for line 1 & 2 and False for line 3. In
other word How do I read line after line of a memo field and process my code
in VBA ?

Is there already done ? Any help would be welcome
 
D

Douglas J Steele

Assuming you're using Access 2000 or newer, store the value in a variable,
and use the Split function to break it into its individual lines. The
following untested aircode should do it:

Dim intLoop As Integer
Dim strMemo As String
Dim strOutput As String
Dim varLines As Variant

strMemo = Me.MyMemoField
varLines = Split(strMemo, vbCrLf)

If IsNull(varLines) = False Then
For intLoop = LBound(varLines) To UBound(varLines)
If InStr(varLines(intLoop), "AAA") > 0 Then
strOutput = strOutput & "AAA appears on line " & intLoop + 1 &
vbCrLf
End If
Next intLoop
Else
strOutput = "Nothing to search."
End If

MsgBox strOutput
 
G

Guest

Thanks it worked perfectly. I realised that in another application, reading
line after line does not make sens. In the same idea, How do you count string
occurences of a string in a memo field ?

XXXAAAXXXXXXXXXXXXXXXXXXXXXXXXXXAAAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXAAAAXXXXXXXXXXXXXXXXXXXXXXXXXXXAAAXXX
--> Found 4 "AAA".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top