UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Print Report Based On Form Sort Order, Access 2010    
 
   
winterolympic
post Mar 14 2017, 11:32 AM
Post#1



Posts: 339
Joined: 26-March 13



Hi, I have a form, frmEmployee and this form has a print button.
Users can sort frmEmployee ascending or descending order by fields and I want to run report the same ascending or descending order.

The print button on the frmEmplyee, I added code like below, but query didn't change.

QUOTE
Private sub cmdPrint_click()
Dim strNewRecord as string
strNewRecord = "SELECT * FROM qryEmployee ORDER BY department"

Me.recordsource = strNewRecord
End sub


The report uses the same qryEmployee.

How can I print preview the same order like frmEmployee?
Thanks.
Go to the top of the page
 
Jeff B.
post Mar 14 2017, 11:58 AM
Post#2


UtterAccess VIP
Posts: 9,651
Joined: 30-April 10
From: Pacific NorthWet


First, are you printing a form, or running a report?

--------------------
Regards

Jeff Boyce
Microsoft Access MVP (2002-2015)

Mention of hardware or software is, in no way, an endorsement thereof. The FTC of the USA made this disclaimer necessary/possible.
Go to the top of the page
 
winterolympic
post Mar 14 2017, 12:11 PM
Post#3



Posts: 339
Joined: 26-March 13



running a report, rptEmployee.

Thanks
Go to the top of the page
 
GroverParkGeorge
post Mar 14 2017, 04:16 PM
Post#4


UA Admin
Posts: 28,880
Joined: 20-June 02
From: Newcastle, WA


Ordering is done within the report, so the sort order of the query that provides those records is not that important. Set it here to sort on the fields you want to sort on within the report.

Attached File  2017_03_14_14_13_33.jpg ( 183.1K )Number of downloads: 0


To do this dynamically, you will have to pass an argument from the form to the report and use that to specify the Order By field in the report.

--------------------
Go to the top of the page
 
doctor9
post Mar 14 2017, 05:15 PM
Post#5


UtterAccess Editor
Posts: 16,845
Joined: 29-March 05
From: Wisconsin


winterolympic,

The key is to set up your report with NO sorting in the Grouping and Sorting dialog box when viewing the report in Design View. Then, in the report's Open event you can check the value of the OpenArgs to see what the sort order is.

For example, if the form's .SortOrder property is "LastName DESC", you'd send that to the report via the OpenArgs argument like this:

CODE
    DoCmd.OpenReport "rptTest", acViewPreview, "", "", acNormal, Replace(Me.OrderBy, "[" & Me.Name & "].", "")


You do the Replace() bit to strip off the name of the form. You see, if your form's name is "frmTest", your .OrderBy property will look like this: "[frmTest].[strSSN] DESC, [frmTest].[Zip Code]" and you only need the field names and the optional "DESC" for descending.

Then, in your report's Open event, you just use the text you passed like this:

CODE
    Me.OrderBy = OpenArgs


Hope this helps,

Dennis

--------------------
(;,;) Li'l Cthulu says: Please talk about what you're trying to do, as well as how you're doing it.
Changing your real table name to "Table1" and your real form name to "Form1" in your posts makes it more difficult to understand what's going on, not easier.
Guidelines for Posting Questions
Go to the top of the page
 
winterolympic
post Mar 20 2017, 11:18 AM
Post#6



Posts: 339
Joined: 26-March 13



Thank you so much! I got it.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    25th March 2017 - 06:36 PM