Function SortTypeValue() As String
If Report.Parameters!SortType.Value = "1" Then
Return "=Fields!StockDesc.Value"
else Return "=Fields!StockCode.Value"
End If
End Function
Then in the sorting tab I have entered in the expression field: =Code.SortTypeValue().
However this is not doing anything. The data is just displayed in the order it is taken from the database. Can this be done? If so can anybody please tell me what I am doing wrong?
Thanks in advance.
Dynamic use of parameters for grouping can be achieved using the following syntax:
=Fields(Parameters!ParamName.Value).Value
Maybe this will also work for sorting
--
Your code is going to return the same value regardless of sort type anyway.
=Fields!StockDesc.Value
You don't need it if the above method works.
--
You can set interactive sorting so the user can sort on any column they wish:
right click on the column header
interactive sort
tick tickbox
set sort expression to the value held in that particular column (i.e. if column is sales amt then =fields!salesamt.value)
done
if you need to do this for a whole raft of columns, it is quicker to do it in the (F4) properties window:
expand the 'user sort' propery and set the 'sort expression' drop down as per the column name
NB keep sort expression selected otherwise when you click on the next column you wish to add a sort to, the properties collapse|||You say my code will return the same value regardless of sort type anyway. Why? Each condition returns a different string.
If I was to use =Fields(Parameters!ParamName.Value).Value I would still need a way to determine which column the user wants to sort on so I know which ParamName to insert.|||To paraphrase the jerky boys "my eyes is going crazy"
but you still don't need the code anyway.
With regards to using my technique for sorting.....
It works.
I just created a very simple report.
I added one parameter called 'sort by'
I just set the values of this to the names of the db columns returned. Spelling exactly as per db cols!
In the table, sorting tab, i just added this
=Fields(Parameters!sortby.Value).Value
go to the preview, Pick your column name, run
simple|||
One step further. . .
Create the parameter as described by "adolf garlic" and also create a parameter named "SortDirection" and give the parameter values "Ascending" and "Descending"
In the table/sort "Expression" field(s) enter:
=Iif(Parameters!SortDirection.Value = "Ascending", Fields(Parameters!SortBy.Value).Value, "")
=Iif(Parameters!SortDirection.Value = "Descending", Fields(Parameters!SortBy.Value).Value, "")
and set the proper direction for both expressions.|||Thanks adolf garlic. Works like a treat. Exactly what I was after.sql
No comments:
Post a Comment