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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting on a form

Status
Not open for further replies.

woodyinoz

IS-IT--Management
Jan 8, 2002
215
GB
Hi all,

I am attempting to create a button upon a form in order to sort the forms table by whatever field(s) the user requires. However, when I use code that shows the user the sort dialog box I get an error telling me that I can't sort a table that is already in use upon a form.

This is causing me problems as the user will be required to continually enter new sort criteria.

Has anyone any ideas as to how I may be able to get around this problem?

Thanks,

Woody.
 
Woody,

In forms, sorting is best handled by changing the current index. Create secondary indexes that sort your table in the various orders you want to supply and then either use the Record | Filter dialog to select the desired index in the Order By list near the bottom, left of the Filter dialog.

(Yes, it's a bit odd to be selecting index order from the Filter dialog.)

You can also add code to switch Indexes on the fly. For example, here's a very basic approach:

Code:
method pushButton(var eventInfo Event)
var
   strIndex String
endVar

const
   USERCANCEL = "{N/A}"
endConst

   switchMenu

      case "Order Number"  : strIndex = ""
      case "Customer No"   : strIndex = "Customer No"
      case "Oldest Orders" : strIndex = "SaleDate"
      case "Newest Orders" : strIndex = "SaleDateDesc"
      case "Order Total"   : strIndex = "TotalInvDesc"

      otherwise       : strIndex = USERCANCEL


   endSwitchMenu

   if strIndex <> USERCANCEL then
      Orders.switchIndex( strIndex, Yes )
   endIf

endMethod

This is based on the Orders sample table. (I've added three secondary indexes to the ones that are already created.) The code is taken from the pushButton event on a button, displays a menu of choices, and changes the active index when the user selects on of the menu commands.

This example also assumes there's a TableFrame on the form named Orders. (There's also a tCursor based approach that can be far more efficient in a networked environment.)

There are several different ways you can allow this, but this is one of the most flexible.

Be aware, though, that this changes the properties of the form. If your users are working with undelivered forms (e.g. the .FSL files), it's possible they'll be prompted to save the form after switching the indexes. If they are, change the IF block as follows:

Code:
   if strIndex <> USERCANCEL then
      Orders.switchIndex( strIndex, Yes )
      DesignModified = No
   endIf

Hope this helps...

-- Lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top