sorting second line, second word

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to sort multi-line notes, separted by 4 hard returns, by the 2nd line,
2nd word. Is it possible to redefine a sort to do this?

Thank you!
 
I need to sort multi-line notes, separted by 4 hard returns, by the 2nd line,
2nd word. Is it possible to redefine a sort to do this?

Thank you!

Ouch. Well, let's see... ASSUMING that "the second word" will reliably
be flanked by blanks, you should be able to extract it with an
expression:

SortKey: Left(Mid([fieldname], InStr(InStr([fieldname], Chr(13) &
Chr(10)), " ",[fieldname])),

Ouch!!! Ok, that's getting MUCH too hairy. Try this instead:

Public Function SortWord(strIn As String) As String
Dim iPos As Integer
Dim strLine As String
iPos = InStr(strIn, Chr(13) & Chr(10)) + 1 ' find 2nd line
strLine = Mid(strIN, iPos)
' trim off first word
strLine = Mid(strLine, InStr(strLine, " ") + 1)
SortWord = Left(strLine, InStr(strLine, " ") - 1)
End Function

This function should have some error trapping to detect ill formed
notes - if the note doesn't in fact have a second line, or the second
line consists of just one or two words, it will fail.

John W. Vinson[MVP]
 
Back
Top