Solved

MS Access: How Can I pass the Sort Order of a subform to a report

Posted on 2015-02-09
5
336 Views
Last Modified: 2016-02-11
How Can I pass the Sort Order of a subform to a report?  Right now, i am able to open the report passing the filtered parameters from the form to the report, but i ll also like to sort. So it passes the filter but not the sort order. Is there a practical wasy to also pass the sort order from the form to the report? The user can chose to sort by any column. Here is the code:

Private Sub CmdPreviewReport_Click()
    Dim stDocName As String
    stDocName = "Report_Name"
    DoCmd.OpenReport stDocName, acPreview, , Me.MainWorkloadQueryForm.Form.Filter    
End Sub
0
Comment
Question by:peterslove53
  • 2
  • 2
5 Comments
 
LVL 84
Comment Utility
Not using that specific method, no - and sorting in a report is much different than a Form, since any groups you have in the report will take precedence.

You could use the OpenArgs method, which would allow you to pass in the Filter and Sort info, and you could then set those in the Report's Open event, but I'm not sure that'll get you what you want.
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
Comment Utility
That's the OrderBy property you could pass in OpenArgs:

DoCmd.OpenReport stDocName, acPreview,,Me.MainWorkloadQueryForm.Form.Filter,,Me.MainWorkloadQueryForm.Form.OrderBy

Then - in the OnOpen event of the report - read and decode this.
It may not be that easy, as it can be, say:

     [CustomerName] Like "International*" And [ProductID] = 45

Sorting must be done in the report, not the source of the report as this will be ignored by the report.

/gustav
0
 

Author Comment

by:peterslove53
Comment Utility
i used the OpenArgs but it ll sort by the column specify. I just want to carry the whole sort order to the report, Since users can sort by any order.
DoCmd.OpenReport stDocName, acPreview, , Me.MainWorkloadQueryForm.Form.Filter, "sort_column"

but it ll sort by the column you specify.
The problem is a user may sort by any column and the report should sort by the appropriate column
0
 

Author Comment

by:peterslove53
Comment Utility
Thank you Gustav, it worked.

I used this code in the onclick event:
 DoCmd.OpenReport stDocName, acPreview,,Me.MainWorkloadQueryForm.Form.Filter,,Me.MainWorkloadQueryForm.Form.OrderBy

and the in the report open event, i put this code:
Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Report_Open
Dim VarSorting As String

If Not IsNull(Me.OpenArgs) Then
VarSorting = Me.OpenArgs
End If

Me.OrderBy = VarSorting
Me.OrderByOn = True 'Apply the sort order

Exit_Report_Open:
Exit Sub
Err_Report_Open:
MsgBox Err.Description
Resume Exit_Report_Open
End Sub
0
 
LVL 49

Expert Comment

by:Gustav Brock
Comment Utility
Great! I had forgotten about the OrderBy property of the report. That makes it easy.

/gustav
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now