Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using parameter prompt to change sort direction - A/Z 1

Status
Not open for further replies.

paqguy

Instructor
Nov 1, 2001
36
US
I've setup a parameter prompt to allow the user to select a sort order of a report. I would also like to allow them to select the direction of the sort - asc or desc. Is this something that can be changed with a formula?

paqguy - Shaun Beane
Instructor/Developer
sbeane@adelphia.net
 
hi
yes you can by a parameter
---------------
1. Create a parameter with 2 default values in the picklist: Descending and Ascending.

NOTE:

In Crystal Reports version 5 or 6, it is not possible to have a pick a parameter value from a list. The user must enter a specific value, guided by the prompting text. For example : To Sort in Ascending order type A, to sort in Descending order type D.

On the 'Insert' menu, click 'Parameter', then click 'New'.

Type the name and prompting text for the parameter in the corresponding boxes.

In the 'Type' box, click 'String'.

Click 'Set Default'.

In the 'Value to add' box, type 'Descending' then click '>' to move it to the 'Default Values' list.

Repeat the above step for 'Ascending'.

Click 'OK', then click 'OK' again to return to the report.


2. Create 2 formulas based on the field you want to change the sort direction on:

On the 'Insert' menu, click 'Formula', then click 'New'.

Create this formula:

@Asc

If {?Parameter} = "Ascending" then {DatabaseField}

Save this formula and close the Formula Editor. This brings you back to the Formula tab of the Insert Fields dialog box.

Click 'New' and create this formula:

@Des

If {?Parameter} = "Descending" then {DatabaseField}

Save this formula and close the Formula Editor.

Click 'Close' to return to the report.


4. Sort the report based on these two formulas.

On the 'Report' menu, click 'Sort Records'.

In the 'Report Fields' list, click {@Asc} and move it to the 'Sort Fields' list.

Under 'Sort Direction', click 'Ascending'.

In the 'Report Fields' list, click {@Des} and move it to the 'Sort Fields' list.

Under 'Sort Direction', click 'Descending'.

Click 'OK' to return to the report.


Once you preview the report you will be prompted to select a parameter value, which will determine how the report is sorted.

---------------------------

cheers

pgtek
 
If the dtabase field is numeric, you can simply sort (ascending) on the following formula:
--------------------------------------------------------
If {?Parameter} = "Ascending" then {DatabaseField} ELSE
-{DatabaseField}
--------------------------------------------------------

In other words, the parameter controls sorting on the field (ascending) or on its negative value (effectively descending).

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Thanks for your help! That was what I needed, it is text, so I used the first one.

Didn't think of checking Crystals knowledge base for that one, but anyhow - thanks for the help.

paqguy - Shaun Beane
Instructor/Developer
sbeane@verizon.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top