Forms and Subform Order By

B

Bryan

I have a form with field labels and then the summary data
below it. Then in a subform i have all the details of the
data. I want to sort the data in the subform using the
labels. On Click the subform data will sort by ascedning
or descending. It works fine if the labels are in the
subform. If the labels are in the main form I cannot get
it to find the OrderBy property. Here is a sample of the
code that works when the labels are placed directly in the
subform.

If SortOrder = "Asc" Or SortField <> "tranvolume" Then
Me.OrderBy = "tranvolume"
SortOrder = "Desc"
ElseIf SortField = "tranvolume" Then
Me.OrderBy = "tranvolume DESC"
SortOrder = "Asc"
End If
SortField = "tranvolume"

When the labels are in the main form, I need a way to call
the subform field tranvolume however I haven't found the
right code. (i.e. something along the lines of Me!
[subformname].OrderBy = tranvolume

Any help would be appreciated.

Bryan
 
T

tina

the name of a subform, as a form object in the database window, in not
necessarily the same as the name of the subform *control* in the main form.
thnk of a subform control as a box (container) that holds the subform - like
a pair of shoes in a box; the shoes are called sneakers, but the box is
called a shoebox.
to determine the name of the subform control:
1. open the main form in design view.
2. in design view, click *once* on the subform to select it.
3. open the Properties box.
4. click on the Other tab.
5. look at the Name property - that is the name of the subform control.

the name you find in #5 above is the name you need to use in the reference.
so if the subform name is Child4 (Access often give a default name of Child#
to subform controls), then the reference would be

Me!Child4.Form.OrderBy

hth
 
G

Guest

Thank you! It is working now (had the right form name must have had other wrong variables wrong), the code looks like

Private Sub TranCount_Click(

'Sort fields if lable is clicked first descending then ascendin

If SortOrder = "Asc" Or SortField <> "trancount" The
Me!performance_sub.Form.OrderBy = "trancount
SortOrder = "Desc"
ElseIf SortField = "trancount" Then
Me!performance_sub.Form.OrderBy = "trancount DESC
SortOrder = "Asc
End I
SortField = "trancount
End Sub
 

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