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
> Order By Sort With Report, Access 2010    
post Sep 7 2019, 02:09 PM

Posts: 49
Joined: 18-April 09

We are trying to use VBA to sort a report during an open, but having no luck. Please help. Here is the VBA statement:
docmd.openreport "name of report",acviewpreview,,,"orderby [mymonth] ASC"
When we run this we get the type mismatch error.
Any suggestions would be extremely appreciated.
Go to the top of the page
post Sep 7 2019, 02:38 PM

UtterAccess VIP
Posts: 11,055
Joined: 10-February 04
From: South Charleston, WV

The fifth argument of .openreport is Window Mode. Did you mean the sixth argument (Openargs)? in which case you need another comma.

Robert Crouser
Go to the top of the page
post Sep 7 2019, 03:27 PM

UtterAccess VIP
Posts: 10,080
Joined: 25-October 10
From: Gulf South USA

Hi: In addition to adding the additional comma, as Robert indicated, I would also remove the "orderby" from the OpenArgs and just use "[mymonth] ASC" ... although the ASC is the default and not necessary.

Then in the OnOpen event procedure of the report, use ...

Private Sub Report_Open(Cancel As Integer)
Me.OrderBy = Me.OpenArgs
Me.OrderByOn = True
End Sub

I would also suggest that you consider using a form control to enter/select the OpenArgs and reference that in the DoCmd.OpenReport command. That way you will not have to dig into the event procedure to change the OpenArgs parameter.


"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
post Sep 8 2019, 12:46 AM

Posts: 1,424
Joined: 2-April 09
From: somewhere out there...

you may do it like this in VBA:
Docmd.OpenReport "name of report",acViewPreview
Reports("name of report").OrderBy="[mymonth] ASC"
Reports("name of report").OrderByOn=True

Never stop learning, because life never stops teaching.
Go to the top of the page
post Sep 9 2019, 06:47 AM

UtterAccess VIP
Posts: 7,968
Joined: 24-May 10
From: Downeast Maine

Do you want the users to be able to specify the sort order? If not, why not just use the report's built-in Order By tool?
Go to the top of the page

Custom Search

RSSSearch   Top   Lo-Fi    15th October 2019 - 08:52 AM