Normal Topic Sorting tableview Subform Records (Read 563 times)
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Sorting tableview Subform Records
Feb 15th, 2013 at 10:50pm
Print Post Print Post  
Sorting tableview Subform Records from CommandButton on the Mainform:

I have tried to accomplish the above using @SpecCommand ( ) as well as @LoadSortSpec ( ) and RunSortSpec.

Code
Select All
var vRun as Int

vRun = @LoadSortSpec("SortDateAscending")
		If vRun = 1
		{
			RunSortSpec()
		}
 



Code
Select All
var vStr as String

vStr = @SpecCommand(SPEC_OPERATION_LOAD, SPEC_TYPE_SORT, "SortDateAscending")

vStr = @SpecCommand(SPEC_OPERATION_RUN, SPEC_TYPE_SORT, "")

 



The problem seems to be there are Sort Spec of mainform and subforms are involved. Because of specificity and Uniqueness of name, the sortspec loads fine, but it confuses as to of which form the sort spec to run for the second part of the code, since the name of the form is not indicated in the code.

I have been using default sorting in the subform and that works fine.

What am I doing wrong?

  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Sorting tableview Subform Records
Reply #1 - Feb 17th, 2013 at 1:58pm
Print Post Print Post  
I'm not sure if the answer that follows is is the best method, since I set it up many years ago, and haven't checked to see if some of the newer commands would do any better than what I have. But, it has worked very well for me.

I began by creating 4 saved sort specs in the parent form. They each have identical specs for the parent, but an assortment of specs for the subform (because a sort spec in the parent will also save the subform sort specs). Then, I have a small button above each of the 4 columns in the subform that I want to sort, which contains code similar to your first example above; except that I don't use RunSortSpec() because that causes the main parent to change to the first record in the result set.

In order to get the sort to take effect, and stay on the same parent record, I simply use FormCommit(""). So, my code looks like this:
Code
Select All
var vSelect as Int

vSelect = @LoadSortSpec("Sort by: Category")

// Saves main record, and re-sorts subform
FormCommit("") 

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Sorting tableview Subform Records
Reply #2 - Feb 17th, 2013 at 5:44pm
Print Post Print Post  
Thanks Carl, it worked well. You always seem to have right answers!! FormCommit ("" ) part does the trick.
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Sorting tableview Subform Records
Reply #3 - Feb 18th, 2013 at 5:38am
Print Post Print Post  
You're welcome! Glad it worked for you.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged