Orderby Property?

D

Don

Instead of haveing to create three different reports, here
is whtat I would like to do.....

I have a button on a form that opens a report in print
Preview mode. For simplicity, let's assume there are only
three fields on this report..... Field1, Field2, Field3.

I'd like to put Radio Buttons on my form, letting the user
choose which of the three fields they wish to sort by.
Now, I can easily create three different reports that will
accomplish this, but of course, I want to expand my
knowledge a little.

How can I accomplish this easily? I see the "order by"
property, but there isn't a good example of how this works
in the Help Files.

Perhaps I have to change the report's recordsource
property?

And when I do this, where do I put the code? Should in be
in the report's "On Open" Event, or should it be in the
Button's "On Click" Event? Any guidance would surely be
appreciated.
 
M

Marshall Barton

Don said:
Instead of haveing to create three different reports, here
is whtat I would like to do.....

I have a button on a form that opens a report in print
Preview mode. For simplicity, let's assume there are only
three fields on this report..... Field1, Field2, Field3.

I'd like to put Radio Buttons on my form, letting the user
choose which of the three fields they wish to sort by.
Now, I can easily create three different reports that will
accomplish this, but of course, I want to expand my
knowledge a little.

How can I accomplish this easily? I see the "order by"
property, but there isn't a good example of how this works
in the Help Files.

Perhaps I have to change the report's recordsource
property?

And when I do this, where do I put the code? Should in be
in the report's "On Open" Event, or should it be in the
Button's "On Click" Event? Any guidance would surely be
appreciated.


In all but trivial reports, a report's sorting should be
specified in the report's Sorting and Grouping window, which
overrides and sorting done in a record source query. The
OrderBy property is only slightly more useful, but still at
a lower priority than Sorting and Grouping.

If you create a group level in the report's design view, you
can then change it in the report's Open event procedure:

If Forms!theform.option1 = True Then
Me.GroupLevel(0).ControlSource = "Field1"
ElseIf Forms!theform.option2 = True Then
Me.GroupLevel(0).ControlSource = "Field2"
ElseIf Forms!theform.option3 = True Then
Me.GroupLevel(0).ControlSource = "Field3"
End If

If you have other group levels in the report, change the 0
to whatever level you have for the sort.
 
G

Guest

There's probably an easier way to do this using the
properties you mentioned, but here's one way.

In the on click event of my command button:

I keep a temporary table that the report uses as its
RecordSource.

Based on the options my user selects, I delete all records
in the table.

Then I use the query I've built from the choices selected
to repopulate the table.

Then I simply open the report.

This probably not what you're looking for, but it does
work.

Hopefully someone posts the correct way so I can pick it
up too.
 

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