Report Sort Oder On Open

Eljefegeneo

Still trying to learn
Local time
Yesterday, 18:53
Joined
Jan 10, 2011
Messages
902
I would like to set the sorting on a report with vba. I know that I can do this via the OnOpen event with code something like:
Code:
  Dim sOrder As String
  sOrder = "[DateOfContact] Asc"
  Me.OrderBy = sOrder
  Me.OrderByOn = True
But want I want do to is set the sOrder from a button on another form from which I open the report. If I set the string for sOrder from an OnClick event to open the report, it doesn't pass to the next event. What I tried was:
Code:
 Dim sOrder As String
  sOrder = "[DateOfContact] Asc"
  DoCmd.OpenReport "rptSalesFollowupPreviousAll2", acViewReport
I hope I am missing something that is obvious, but I just cannot figure out what to do.
 
Hi. If I am understanding your question correctly, you could try referring to the opened report like so:


Reports!ReportName.OrderBy = "FieldName"
Reports!ReportName.OrderByOn = True


Hope it helps...
 
As I figured, something so simple I was missing it. But just curious, is there away of passing the variable from the one form to the report OnOpen event.
 
As I figured, something so simple I was missing it. But just curious, is there away of passing the variable from the one form to the report OnOpen event.
Yes, you can use the OpenArgs argument of the OpenReport method.
 

Users who are viewing this thread

Back
Top Bottom