By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,538 Members | 2,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,538 IT Pros & Developers. It's quick & easy.

Using OrderBy to dynamically change sort order in reports

P: n/a
The following code is used in my db to change the sort order of the
report to various fields. I want to take this one stage further and
use maybe a Case Select to give 2 or 3 different options to sort the
report.

Is ther any way I can adress the report name as is used in strDocName
and strSQL so instead of having

Reports![Summary Information Report].OrderBy = strSQL

I could Dim reportstr as String

and use

Reports![reportstr].OrderBy = strSQL
This way i could probably hold all of the info in a table and call up
the fields as required to specify report name and sort option...... I
realise it may not be possible, or it may be and it is an issue of
syntax which I have not grasped.
Thanks.

fecket
Example Code

Private Sub annsummaryprev_Click()
On Error GoTo Err_annsummaryprev_Click

DoCmd.SetWarnings False
Dim stDocName As String

stDocName = "Create Summary Info Table Query"
DoCmd.OpenQuery stDocName, acViewNormal

stDocName = "Summary Information Report"

Dim strSQL As String
strSQL = "CatASubmarine"

DoCmd.OpenReport stDocName, acPreview
Reports![Summary Information Report].OrderByOn = True
Reports![Summary Information Report].OrderBy = strSQL
DoCmd.SetWarnings True
Exit_annsummaryprev_Click:
Exit Sub

Err_annsummaryprev_Click:
MsgBox Err.Description
Resume Exit_annsummaryprev_Click

End Sub
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sun, 13 Mar 2005 21:48:14 +0000, fecket <ne*********@hotmail.com>
wrote:

Yes. Use syntax like:
Reports(reportstr).OrderBy = strSQL

-Tom.

The following code is used in my db to change the sort order of the
report to various fields. I want to take this one stage further and
use maybe a Case Select to give 2 or 3 different options to sort the
report.

Is ther any way I can adress the report name as is used in strDocName
and strSQL so instead of having

Reports![Summary Information Report].OrderBy = strSQL

I could Dim reportstr as String

and use

Reports![reportstr].OrderBy = strSQL
This way i could probably hold all of the info in a table and call up
the fields as required to specify report name and sort option...... I
realise it may not be possible, or it may be and it is an issue of
syntax which I have not grasped.
Thanks.

fecket
Example Code

Private Sub annsummaryprev_Click()
On Error GoTo Err_annsummaryprev_Click

DoCmd.SetWarnings False
Dim stDocName As String

stDocName = "Create Summary Info Table Query"
DoCmd.OpenQuery stDocName, acViewNormal

stDocName = "Summary Information Report"

Dim strSQL As String
strSQL = "CatASubmarine"

DoCmd.OpenReport stDocName, acPreview
Reports![Summary Information Report].OrderByOn = True
Reports![Summary Information Report].OrderBy = strSQL
DoCmd.SetWarnings True
Exit_annsummaryprev_Click:
Exit Sub

Err_annsummaryprev_Click:
MsgBox Err.Description
Resume Exit_annsummaryprev_Click

End Sub


Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.