sorting second line, second word

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!
 
J

John Vinson

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]
 

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