Report using subform Order By and Filter values

H

h2fcell

Hello I’m using Access 2007
I have a form and report question. I have a form “frmAgy5_1†with a
datasheet view of a subform “sbfAgy5_1â€. Below the subform I have a Print
Preview button with an “On Click†event [Embedded Macro] with OpenReport
rptAgy5_1

I would like to open rptAgy5_1 using the “Order By†and “Filter†value of
the subform “sbfAgy5_1â€.
This will insure the report captures any filters or sorts a user has
applied to the subform.

The subform and report are both based on the same Record Source.
Should I be using an [Event Procedure] instead? If so what should the code
look like.

I’m guessing something like the below. Of course the below doesn’t work.

Private Sub cmdPrintPreview_Click()
Dim myFilter As String
Dim myOrder As String

myFilter = Forms!sbfAgy5_1.Filter
myOrder = Forms!sbfAgy5_1.OrderBy

DoCmd.OpenReport "rptAgy5_1", acViewPreview, , myFilter, acWindowNormal

End Sub
 
J

June7 via AccessMonster.com

I do a very similar thing but since I don't use macros it is in button click
event ([EventProcedure]).
My code refers to the container control that holds the subform, so suggest:
myFilter = Me.yourSubformContainerNameHere.Form.Filter
myOrder = Me.yourSubformContainerNameHere.Form.OrderBy

You want to change the record order from what is set up in the report's
record source query? I have changed the record source query statement of a
report by passing the string in the OpenArgs argument of the OpenReport and
then extracting it in the Open event of the report. Ex:

Private Sub Report_Open(Cancel As Integer)
Me.RecordSource = Me.OpenArgs
End Sub

Perhaps can do same with OrderBy property.
Hello I’m using Access 2007
I have a form and report question. I have a form “frmAgy5_1†with a
datasheet view of a subform “sbfAgy5_1â€. Below the subform I have a Print
Preview button with an “On Click†event [Embedded Macro] with OpenReport
rptAgy5_1

I would like to open rptAgy5_1 using the “Order By†and “Filter†value of
the subform “sbfAgy5_1â€.
This will insure the report captures any filters or sorts a user has
applied to the subform.

The subform and report are both based on the same Record Source.
Should I be using an [Event Procedure] instead? If so what should the code
look like.

I’m guessing something like the below. Of course the below doesn’t work.

Private Sub cmdPrintPreview_Click()
Dim myFilter As String
Dim myOrder As String

myFilter = Forms!sbfAgy5_1.Filter
myOrder = Forms!sbfAgy5_1.OrderBy

DoCmd.OpenReport "rptAgy5_1", acViewPreview, , myFilter, acWindowNormal

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top