General discussion

Locked

Crystal 8.5 Sort by variable

By Walkerxp92 ·
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.

This conversation is currently closed to new comments.

10 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Walkerxp92 In reply to Crystal 8.5 Sort by varia ...

Point value changed by question poster.

Collapse -

by ChandraRam In reply to Crystal 8.5 Sort by varia ...

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

Collapse -

by Walkerxp92 In reply to

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.

Collapse -

by ChandraRam In reply to Crystal 8.5 Sort by varia ...

By "column" do you mean the column in your report or the table used in the report?

Collapse -

by Walkerxp92 In reply to

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.

Collapse -

by Regg In reply to Crystal 8.5 Sort by varia ...

>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)

Collapse -

by Walkerxp92 In reply to

Poster rated this answer.

Collapse -

by ChandraRam In reply to Crystal 8.5 Sort by varia ...

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.

Collapse -

by Walkerxp92 In reply to

Poster rated this answer.

Collapse -

by Walkerxp92 In reply to Crystal 8.5 Sort by varia ...

This question was closed by the author

Back to Software Forum
10 total posts (Page 1 of 1)  

Related Discussions

Related Forums