peterslove53
asked on
MS Access: How Can I pass the Sort Order of a subform to a report
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.F orm.Filter
End Sub
Private Sub CmdPreviewReport_Click()
Dim stDocName As String
stDocName = "Report_Name"
DoCmd.OpenReport stDocName, acPreview, , Me.MainWorkloadQueryForm.F
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.F orm.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
DoCmd.OpenReport stDocName, acPreview, , Me.MainWorkloadQueryForm.F
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
ASKER
Thank you Gustav, it worked.
I used this code in the onclick event:
DoCmd.OpenReport stDocName, acPreview,,Me.MainWorkload QueryForm. Form.Filte r,,Me.Main WorkloadQu eryForm.Fo rm.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
I used this code in the onclick event:
DoCmd.OpenReport stDocName, acPreview,,Me.MainWorkload
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
Great! I had forgotten about the OrderBy property of the report. That makes it easy.
/gustav
/gustav
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.