Sort a report based on options on a form

A

Angel_G

I need to sort a Report (Itemssold_rpt) based on what a user selects in a
form (ItemsSold_frm with SortBy option group). The report contains Item.
Item Desc, Date, Etc. The sortBy option groups stores the values in numeric
format for example Sort by Item is equal to 1 and Sort by Description is
equal to 2.
Can I put some kind of code in the Sort option field for the report that
will sort the report accordingly?
Can someone help me with the right code format for this field?
I have tried it myself but no luck.
Thanks in advance
 
G

Guest

Hi, Angel.

See VBA Help on the form's OrderBy property. Based on selections in your
form fields, you will need to build a valid OrderBy string expression, assign
the OrderBy property, the OrderByOn property to True, and open the report:

Dim stDocName As String
Dim stFilter As String

stDocName = "YourForm"
stFilter = 'Assign filter here
With Reports(stDocName)
.OrderBy = stFilter
.OrderByOn = True
End With
DoCmd.OpenReport stDocName, acPreview

Hope that helps.
Sprinks
 
M

Marshall Barton

Angel_G said:
I need to sort a Report (Itemssold_rpt) based on what a user selects in a
form (ItemsSold_frm with SortBy option group). The report contains Item.
Item Desc, Date, Etc. The sortBy option groups stores the values in numeric
format for example Sort by Item is equal to 1 and Sort by Description is
equal to 2.
Can I put some kind of code in the Sort option field for the report that
will sort the report accordingly?


Kind of crude, but you can use the expression:

=IIf(Forms!ItemsSold_frm.SortBy = 1, Item, Description)

A better approach would be to use a little code in the
report's Open event procedure that copies the name of the
sort field (not a code number) from a form control to the
appropriate GroulLevel entry's control source.

Me.GroupLevel(0?).ControlSource = Forms!ItemsSold_frm.SortBy
 
G

Guest

Duane,

Thanks for the post. This approach is much more flexible and powerful.

Sprinks
 

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