Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1512
  • Last Modified:

Need sort ascending visual basic code.

Sub form data, that is retrieving data from a query will not sort according to set query properties.  I seem to need to force the sort on the subform as it is being accessed using visual basic.  I need a sort ascending line of visual basic code, unless there is another way.
Thanks
0
Tetsinger
Asked:
Tetsinger
  • 2
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Hi Tetsinger,

You'll need to use your subform's Order By property to sort within the subform.  

One trick I do all the time is to have toggle buttons that look like column headers in my button.  Push the button down, your subform sorts A-Z by that field by editing the OrderByOn property.  Push it again, it sorts Z-A.  Let me know if you'd like the code.

Hope this helps.
-Jim
0
 
TetsingerAuthor Commented:
Greetings:
I had already set the subform's property to sort withing the subform.  But when I bring up the database from a fresh start up, the subform data is still not sorted.  I'm not sure what you're getting at in your second paragraph.  

I thought if I just put in a couple simple lines of code to directly sort the subform data I could override whatever is causing it to be out of sorts (so to speak).  For example, this is where I was heading:
     DoCmd.GoToControl "gpsbx"
     DoCmd.DoMenuItem acFormBar, acRecordsMenu, ??, , acMenuVer70

However I can't get the ?? part of the code right.

I found this property setting below, but do not know how to implement it or if it is appropriate.

acCmdSortAscending

Do you have another idea?
0
 
shanesuebsahakarnCommented:
Forms!MyMainForm!MySubformControlName.Form.OrderBy="[MyField]"
Forms!MyMainForm!MySubformControlName.Form.OrderByOn=True

Ensure that MySubformControlName is the name of the subform control and not the subform itself (design the main form, click once on the subform and check its Name property in the properties window).
0
 
shanesuebsahakarnCommented:
(which is what Jim was getting at)
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now