Button to order a field on a subform RRS feed

  • Question

  • I have a form containing (mainform) two sub forms (sub1 and sub2).  Both of the sub forms contain several fields and the dataset is pulled for a SELECT query (linked to SQL Server).  The view for each of the forms is a datasheet.

    I have a button on the main form, when selected I want it to sort both of the sub forms by a specific field (sub1.field1 and sub2.field1) on each of the sub forms in ascending order.  Please can anyone help.

    Tuesday, November 10, 2015 7:18 PM


All replies

  • with me.sub1_controlname.form
       .OrderBy = "field1"
       .OrderByOn = true
    end with

    with me.sub2_controlname.form
       .OrderBy = "field2"
       .OrderByOn = true
    end with

    Warm Regards, Crystal * (: have an awesome day :)

    Tuesday, November 10, 2015 7:23 PM
  • Here's another way to write it into the "On Click" event of your button.

    Forms!NameOfYourMainForm.NameOfYourSub1Form.Form.OrderBy = "[NameOfYourSelectQuery].[field1]"
    Forms!NameOfYourMainForm.NameOfYourSub1Form.Form.OrderByOn = True

    Forms!NameOfYourMainForm.NameOfYourSub2Form.Form.OrderBy = "[NameOfYourSelectQuery].[field1]"
    Forms!NameOfYourMainForm.NameOfYourSub2Form.Form.OrderByOn = True

    If this post answered or helped you find the answer to your question, please mark it as such for other Forum users knowledge.

    • Edited by DriveEV Tuesday, November 10, 2015 7:38 PM
    Tuesday, November 10, 2015 7:38 PM
  • it is more efficient with use With object ... End With than referencing the same object multiple times ~

    also, the name of the query or table is only required if the same field name is in the RecordSource multiple times.  If not, then it is NOT referenced this way ...

    Warm Regards, Crystal * (: have an awesome day :)

    Tuesday, November 10, 2015 8:30 PM