It's possible that more than one line-ending character may be in use within
the same string, because you get a different character when you press
Ctrl+Enter than when you press Enter alone. Other line ending characters may
potentially be present if data has been imported from other sources. The
technique I use in Access 2000 and later is to first replace all these
characters with null characters, then replace any sequences of multiple null
characters with single null characters, and finally use the Split function
with the null character as the delimiter ...
Public Function SplitLines(ByVal strInput As String) As Variant
Dim lngCounter As Long
Dim strOutput As String
Dim strChar As String
strOutput = strInput
For lngCounter = 10 To 13
strChar = Chr$(lngCounter)
strOutput = Replace(strOutput, strChar, vbNullChar, 1, -1,
vbBinaryCompare)
Next lngCounter
Do While InStr(1, strOutput, vbNullChar & vbNullChar) > 0
strOutput = Replace(strOutput, vbNullChar & vbNullChar, vbNullChar,
1, -1, vbBinaryCompare)
Loop
SplitLines = Split(strOutput, vbNullChar, -1, vbBinaryCompare)
End Function
Public Sub TestSplitLines()
Dim strTest As String
Dim varTest As Variant
Dim varLoop As Variant
strTest = "This is the first line" & Chr$(10) & _
"and this is the second line" & Chr$(11) & _
"and this is the third line" & Chr$(12) & _
"and this is the fourth line" & Chr$(13) & _
"and this is the fifth line" & Chr$(13) & Chr$(10) & _
"and this is the sixth and final line"
varTest = SplitLines(strTest)
For Each varLoop In varTest
Debug.Print varLoop
Next varLoop
End Sub
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com
The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.