How Can I Sort an ADO Table on a Fieldname Containing a Space?
Have you tried surrounding the fieldname by square brackets? for example:
ArticlesTable.Sort := '[LAST NAME]';
lkessler
I'm a Programmer and a Genealogist. I am the developer of the Genealogy Software: Behold Also the DNA Analysis Software: Double Match Triangulator I operate the GenSoftReviews site My blog | My Tweets | Brute Force If you're into Genealogy, I recommend you try the Genealogy and Family History Stack Exchange site at: http://genealogy.stackexchange.com/ See My Family Research and Unsolved Mysteries
Updated on June 17, 2022Comments
-
lkessler almost 2 years
I am using Delphi, but this is a simple and general problem:
I'm doing the following:
var ArticlesTable: TADOTable; begin ArticlesTable.DisableControls; ArticlesTable.Sort := 'CITY'; ArticlesTable.First; while not ArticlesTable.Eof do begin ... ArticlesTable.Next; end;
This works very well and allows me to efficiently process the records one by one with the records ordered ascending by the CITY field as they are coming in.
However, now I wanted to order by the field "LAST NAME" which has an embedded space in it. But when I use the statement:
ArticlesTable.Sort := 'CITY';
I get the error message:
EOleException: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
I have seen the help on the SORT string syntax. It says to separate multiple fields by commas, and to add ASC or DESC after a field to sort ascending or descending. But it doesn't say what to do if a fieldname has a space in it.
I've tried putting the field name in single and double quotes and even using #20 as the space character, but those don't work.
I can't change the field name on the Microsoft Access database, because there are other programs I don't work with that depend on it.
I'm sure there must be an easy way to do this that I don't know about.
-
lkessler over 14 yearsThank you!! That's the syntax I didn't know about that I needed.
-
lkessler over 14 yearsHooray again for StackOverflow. I spent almost an hour searching the web, not knowing exactly where to look, but skamradt answered me in about 3 minutes.
-
David-W-Fenton over 14 yearsIt sure would be nice if Access scolded you when you tried to create a fieldname with a space in it!