Gkirkup
03-03-2009, 08:53 AM
I have a report which prints in date order. I would like to add another print button, to print the same report in alphabetical order.
I would like to avoid creating a second report, just to change the order. Is there any way to change the order of the report, depending on how the report is selected?
Or is there a way to use a different subform (this one in alphabetical order) depending on how the main report is selected?
Robert
KenHigg
03-03-2009, 09:13 AM
I would consider using the openargs property of the report to indicate which version to to run.
Gkirkup
03-03-2009, 09:40 AM
Ken: I am not familiar with openargs. My instruction to open the report is presently:
DoCmd.OpenReport stDocName, acPreview
Do I simply add a comma and argument to that? Then how do I pick up the argument within the report?
Thanks.
Robert
KenHigg
03-03-2009, 09:55 AM
Looks like it's the 7th argument:
OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)
Then you use it with something like:
me.openargs
Gkirkup
03-04-2009, 03:15 PM
Ken: The report uses a subform to print the records. So I need to change the record source in the subform to a query in date order, to a similar query in alpahbetical order. I have the two queries, but don't know how to change the record source. Could I use 'On open' to do that? Then if 'me.parent.openargs = TRUE' then set the record source to the other query? (my open argument is TRUE when requesting one order, FALSE for the other order).
Or is there a much easier way to do this?
Robert
wiklendt
03-04-2009, 05:06 PM
i've used the one query to display three different sets of data: all results, negative results, and positive results:
On Error GoTo Err_cmdPrintHepALL_Click
Dim stDocName As String
strIsolatePCRresult = ""
stDocName = "rptIsolates_PCR_Hep"
DoCmd.OpenReport stDocName, acPreview, , strIsolatePCRresult, acDialog
Exit_cmdPrintHepALL_Click:
Exit Sub
Err_cmdPrintHepALL_Click:
MsgBox Err.Description
Resume Exit_cmdPrintHepALL_Click
End Sub
Private Sub cmdPrintHepNEG_Click()
On Error GoTo Err_cmdPrintHepALL_Click
Dim stDocName As String
Dim strIsolatePCRresult As String
strIsolatePCRresult = "[Result] = 0 "
stDocName = "rptIsolates_PCR_Hep"
DoCmd.OpenReport stDocName, acPreview, , strIsolatePCRresult, acDialog
Exit_cmdPrintHepALL_Click:
Exit Sub
Err_cmdPrintHepALL_Click:
MsgBox Err.Description
Resume Exit_cmdPrintHepALL_Click
End Sub
Private Sub cmdPrintHepPOS_Click()
On Error GoTo Err_cmdPrintHepALL_Click
Dim stDocName As String
Dim strIsolatePCRresult As String
strIsolatePCRresult = "[Result] > 0"
stDocName = "rptIsolates_PCR_Hep"
DoCmd.OpenReport stDocName, acPreview, , strIsolatePCRresult, acDialog
Exit_cmdPrintHepALL_Click:
Exit Sub
Err_cmdPrintHepALL_Click:
MsgBox Err.Description
Resume Exit_cmdPrintHepALL_Click
End Sub
as you can see, my source report is the same in all button instances, it's just my filter triggered by each button which restricts the report one way or another. the OpenArgs for reports, i thought, is a WHERE statement, but there may be a way to fit ORDER BY in there instead... alternatively, you can add code to the format event on a report. i have used the code below to not/display subreports if a user wants by having check boxes on the form where the button invoking the report is - when the report opens, it checks the status of each checkbox and displays the data accordingly. you can alter this code and put code in to alter the rowsource for the report...
Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As Integer)
If Forms!frmHorse.chkMassage_Observations = False Then
rptHorseMassage_Observations.Visible = False
End If
If Forms!frmHorse.chkMassage_recommendations = False Then
rptHorseMassage_Recommendations.Visible = False
End If
If Forms!frmHorse.chkMassage_glossary = False Then
rptHorseMassage_Glossary.Visible = False
End If
End Sub