Discussion Locked

Crystal 8.5 Sort by variable

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am trying to make a report to sort based on what the user selects. For example I have 4 different columns and I want when the user runs the report he selects from the begining what column to sort by. I do not want the user to have to open up the report in crystal and change the sort by.

10 replies

by chandraram

I've not used Crystal 8.5, but in earlier versions, I would do this using the SortFields property of the Crystal Reports object.

by walkerxp92

Not quite what I am looking for... I do know how to choose what to sort but I want to make parameter field that will allow me to choose what column I want to sort by.

by walkerxp92

column in the report... exp: I have a report that pulls 8 columns from sql and 4 of those I want to sort by but not at the same time, I want the report to have a parameter select field in the beginning that asks the user running the report to choose which column to sort by.

by regg

>Not quite what I am looking for... I do know how to choose what to sort but I want to make parameter field that will allow me to choose what column I want to sort by.<

But this is what you asked for and the given answer is correct.

If the user selects on your form grid a certain column, then:
TheFieldName = DataGrid1.Columns(DataGrid1.Col).DataField
or
TheFieldName = DataGrid1.Columns(DataGrid1.SelStartCol).DataField

then you pass that column to CR as a sort parameter.
If you are using the OCX then that would be, just as already given:

CrystalReport1.SortFields(0) = "+{" & TheTableName & "." & TheFieldName & "}"

Because SortFields is an array make sure you you clear any other defined sort parameters (i.e. in a previous printing the sort parameter may have 2 fields defined under SortFields(0) and SortFields(1). If you do not clear SortFields(1)="" then it remains as previously defined. You can also use the Reset method to clear all)

by chandraram

Let us say you have the sql stored in an ADO object - you can present the names of the fields to the user in some form (a listview?) where by any item can be selected, this field name can then be used to set the SortField property of the CR object.

This discussion is closed to new replies.