I am creating a chemical database that contains a field with chemical names
like 2,4-trifuoro... and 1,1,1-dinitro... I want to alphabetize the list to
ignore the leading numbers. How does one do a sort to ignore anything before
the first actual letter?
That's going to be tricky - inefficient at best, and probably
difficult to program. How big is the table? If you're sorting CAS's
umpteen million names you're in trouble! <g>
I'd suggest adding a Sortkey field, and writing a VBA function to fill
it. I would presume that you would like 1,2-difluorobenzene to sort
before 1,3-difluorobenzene, so you don't want to totally *ignore* the
numbers; with a sortkey field containing only the alpha characters you
could sort first by it, and (for a rough cut) second by the name
itself.
Air code, untested, to extract only the letters:
Public Function JustLetters(strName As String) As String
Dim strWork As String
Dim iPos As Integer
Dim iChr As Integer
JustLetters = "" ' initialize return value
strWork = UCase(strName) ' get all text into upper case
For iPos = 1 to Len(strWork) ' loop through the name
iChr = Asc(Mid(strWork, iPos, 1)) ' get the ASCII value of each letter
If iChr >= 65 And iChr <= 90 Then ' in range A to Z?
JustLetters = JustLetters & Chr(iChr) ' append the letter
Next iPos
End Function
If you add the Sortkey field, and then run an Update query updating it
to
JustLetters([chemicalnamefield])
you can hopefully get something useful for sorting.
John W. Vinson[MVP]