Referencing a subform within a form when using ORDER by Method

J

John

I am trying to utilize a button in a subform within a main
form in order to sort the subform. Here is the code I am
trying to use in order to sort the subform.

Forms![Main]![PersonnelAlpha].OrderBy = "Pager" & " DESC"
Forms![Main]![PersonnelAlpha].OrderByOn = True
Forms![Main]![PersonnelAlpha].Requery

The error message I get is "Object doesn't support this
method or property".

What is the correct syntax to call this order by method
from a subform within a form.

Thanks,
John
 
G

Graham Mandeno

Hi John

When you say Forms![Main]![PersonnelAlpha], you are referring to the subform
*control* on the main form, not the Form object contained within it. A
subform control does not have properties such as OrderBy, hence the error
you are receiving.

To correct this, you can use the control's Form property:

Forms![Main]![PersonnelAlpha].Form.OrderBy = "Pager" & " DESC"
.... and the same for the other two lines.

However, you say you are running this code from a button on the subform.
And form can refer to itself as "Me", so you can simplify this to:
Me.OrderBy = "Pager" & " DESC"
Me.OrderByOn = True

The Requery is unnecessary and can be omitted.
 
J

John Vinson

I am trying to utilize a button in a subform within a main
form in order to sort the subform. Here is the code I am
trying to use in order to sort the subform.

Forms![Main]![PersonnelAlpha].OrderBy = "Pager" & " DESC"
Forms![Main]![PersonnelAlpha].OrderByOn = True
Forms![Main]![PersonnelAlpha].Requery

The error message I get is "Object doesn't support this
method or property".

What is the correct syntax to call this order by method
from a subform within a form.

Since the code is on the subform, I'd just use the builtin Me! operand
to refer to the current form - it needn't deal with the mainform or
the subform control at all. Just Me.OrderBy = <etc>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top