Nominate a column in form to sort descending

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Nominate a column in form to sort descending

Post by Pat »

I have a crosstab query as a source of a form and would like to nominate a column to sort on before it displays the form.

How do I do that?

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Nominate a column in form to sort descending

Post by Pat »

I put the following code into the form's OnOpen Event:
Me.OrderByOn = True
me.OrderBy = "[query name got from record source].[value obtained from Label1.caption] DESC

It saves me having to display the form then choosing the column and choosing UpArrow in the ribbon

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Nominate a column in form to sort descending

Post by HansV »

Another way would be to set the sort order in the crosstab query.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Nominate a column in form to sort descending

Post by Pat »

How would you do that, on the value field? if so, how do you determine which column you are sorting?

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Nominate a column in form to sort descending

Post by HansV »

Ah, OK. If the columns of the crosstab query are fixed, you could create a new query based on the crosstab query, specify the sort order there, and use the new query as record source. Otherwise, setting the sort order in the On Open event is better, and it is probably easier in any case.
Best wishes,
Hans

Pat
5StarLounger
Posts: 1148
Joined: 08 Feb 2010, 21:27

Re: Nominate a column in form to sort descending

Post by Pat »

Yes thanks, it is a dynamic query.
I have a OnClick of all the Label headings where I set it up to sort on a selected column.