Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form's OrderBy to Report.

Status
Not open for further replies.

burcher

Technical User
Apr 26, 2004
22
0
0
US
I am trying to send the Form's Orderby and Filter Parameter to a report. I have got the Filter parameter to pass to the report, but I can't figure out how to pass the OrderBy parameter. Here's what I have so far:

Private Sub Command47_Click()
On Error GoTo Err_Command47_Click

Dim stDocName As String

stDocName = "Select, Patient Lookup"

If Me.FilterOn Then
DoCmd.OpenReport stDocName, acViewPreview, , Me.Filter
Me.OrderBy = Me.OrderBy
Me.OrderByOn = True

Else
DoCmd.OpenReport stDocName, acViewPreview
Me.OrderBy = Me.OrderBy
Me.OrderByOn = True

Anyone got a suggestion?
 
Hi

I see nothing in your code which sets the reports .OrderBy property

In the on open event of the report try code like

Me.OrderBy = Forms!MyFormName.OrderBy
Me.OrderByOn = True

where MyFormName is the name of your form

the form must be open at the time the report runs to use this method

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Yeah, I tried that also, but it still isn't recognizing the OrderBy parameter. But I set it up again so I could let you look at it and see if I'm just missing something.
Private Sub Command47_Click()
On Error GoTo Err_Command47_Click

Dim stDocName As String

stDocName = "Select, Patient Lookup"

If Me.FilterOn Then
DoCmd.OpenReport stDocName, acViewPreview, , Me.Filter
Me.OrderBy = Forms![Patient Summary Data Form].OrderBy
Me.OrderByOn = True

Else
DoCmd.OpenReport stDocName, acViewPreview
Me.OrderBy = Forms![Patient Summary Data Form].OrderBy
Me.OrderByOn = True

End If

Exit_Command47_Click:
Exit Sub

Err_Command47_Click:
MsgBox Err.Description
Resume Exit_Command47_Click

End Sub

Let me know if you see anything I put incorrectly. Thanks
 
Hi

The code is not in the Form Open event, it is in a button click event, presumably on the form

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Right, I have a button to run the report on the form. I have them click in the field that they wish to sort or filter, then when they have the information the way they want it, they click the run report button (on the form)and it pulls up the report using the parameters (filter & Sort) that they preformed on the form. But the sort will not carry to the report, only the filter.
 
Hi!

The lines:
[tt] Me.OrderBy = Forms![Patient Summary Data Form].OrderBy
Me.OrderByOn = True[/tt]

Should not be in the forms button click event, but in the reports on open event (presumably where you set the filteron and filter property of the report using the openargs of the report)

Me - refers to the current form or report.

Roy-Vidar
 
I would never rely on a report's OrderBy property since if you have any values set in the Sorting and Grouping (which you should), the OrderBy will be ignored. The only reliable method is to use code similar to Allen Browne's sample at
Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top