Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Sort by Field Name in ASP

Status
Not open for further replies.

putts

Programmer
Dec 13, 2002
93
US
I have this code currently..
Set DatabaseField = session
("oRpt").Database.Tables.Item(1).Fields.Item
(1)
session
("oRpt").RecordSortFields.Add
DatabaseField, 1

But the value I`m going to have to be able
to sort by is the field name, not its
ordinal.

Is there a way to add this sort by field
name or grab the field Object by knowing
its name?
 
Solved:

Set DatabaseTableCol = session("oRpt").Database.Tables
for i=lbound(arrSort) to ubound(arrSort)
if arrSort(i) <> &quot;&quot; then
for j=0 to DatabaseTableCol.Count
Set DatabaseTable = DatabaseTableCol.Item(j)
for k=1 to DatabaseTable.Fields.Count
if (DatabaseTable.Fields.Item(k).Name = arrSort(i)) then
session(&quot;oRpt&quot;).RecordSortFields.Add DatabaseTable.Fields.Item(k), 0
end if
next
next
end if
next

In this example, arrSort is an array of a bunch of field names (e.g. {Customers.FirstName},{Customers.LastName}) placed into the array in the order to be sorted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top