sorting a subform from a command button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a subform that I'd like to have resorted when a command button is
clicked. The subform uses a table as it's control source. When the form is
opened the subform comes up sorted by values set in the Order By property of
the subform (ie: Order By: table1.Field1) which is correct..

the problem is when the button is clicked. I have the following code:

Forms![MyForm]![table1 subform].OrderBy = "[Field2]"
Forms![MyForm]![table1 subform].OrderByOn = True

I keep on getting the following message after the first line is executed:
"object doesn't support property method "

any help is appreciated again in advance.. Thanks!
 
samymelbourne said:
I have a subform that I'd like to have resorted when a command button
is clicked. The subform uses a table as it's control source. When the
form is opened the subform comes up sorted by values set in the Order
By property of the subform (ie: Order By: table1.Field1) which is
correct..

the problem is when the button is clicked. I have the following code:

Forms![MyForm]![table1 subform].OrderBy = "[Field2]"
Forms![MyForm]![table1 subform].OrderByOn = True

I keep on getting the following message after the first line is
executed: "object doesn't support property method "

any help is appreciated again in advance.. Thanks!

Your syntax is trying to apply the order to the subform *control* not the
form within it. You need...

Forms![MyForm]![table1 subform].Form.OrderBy = "[Field2]"
Forms![MyForm]![table1 subform].Form.OrderByOn = True

The above assumes that the name of the subform control is the same as the
name of the form within. This is the default if you created the subform
with the wizard or by dragging it from the db window, but you should
double-check. The syntax above needs the name of the control, not the form.
 
Thanks for the help.. It makes sense now..

Rick Brandt said:
samymelbourne said:
I have a subform that I'd like to have resorted when a command button
is clicked. The subform uses a table as it's control source. When the
form is opened the subform comes up sorted by values set in the Order
By property of the subform (ie: Order By: table1.Field1) which is
correct..

the problem is when the button is clicked. I have the following code:

Forms![MyForm]![table1 subform].OrderBy = "[Field2]"
Forms![MyForm]![table1 subform].OrderByOn = True

I keep on getting the following message after the first line is
executed: "object doesn't support property method "

any help is appreciated again in advance.. Thanks!

Your syntax is trying to apply the order to the subform *control* not the
form within it. You need...

Forms![MyForm]![table1 subform].Form.OrderBy = "[Field2]"
Forms![MyForm]![table1 subform].Form.OrderByOn = True

The above assumes that the name of the subform control is the same as the
name of the form within. This is the default if you created the subform
with the wizard or by dragging it from the db window, but you should
double-check. The syntax above needs the name of the control, not the form.
 
Back
Top