Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Grouping report at runtime Post Reply Post New Topic
Author Message
Alexeixx3
Newbie
Newbie
Avatar

Joined: 19 Oct 2007
Location: Mexico
Online Status: Offline
Posts: 3
Quote Alexeixx3 Replybullet Topic: Grouping report at runtime
    Posted: 19 Oct 2007 at 1:39pm
Hi all
Can anyone tell me how to perform grouping of a crystal report
 
The field to group on is variable (selected by the user at runtime)
 
If anyone has any axamples, please let me know
 
Thank you
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 21 Oct 2007 at 9:31am
I assume the user is selecting the group based on a parameter.  So, this is actually fairly easy.
 
Create a formula that looks something like this (not know what your groups are, I'm writing this base on my data):
if {?GroupName} = 'Loan Number' then
  {loan.loan_number}
else if {?GroupName} = 'Property State' then
  {loan.property_state}
else if {?GroupName} = 'Posting Date' then
  ToText({loan.posting_date}, 'yyyyMMdd')
All of the results have to be in the same format - string, number, etc. - so you may have to do some conversion based on the field type.   So, you can see that I converted the date field to text.  When you're working with dates that have been converted to text, you have to format them differently when you're using them to sort data than if you're just displaying them because they'll sort in text order instead of in date order. 
 
Once you have your formula set up, use that as your group instead of a specific field.
-Dell


Edited by hilfy - 21 Oct 2007 at 9:32am
IP IP Logged
Alexeixx3
Newbie
Newbie
Avatar

Joined: 19 Oct 2007
Location: Mexico
Online Status: Offline
Posts: 3
Quote Alexeixx3 Replybullet Posted: 26 Oct 2007 at 7:33am
Hey hilfy thanks a lot for your answer
I just tried it and it works great!!!
 
I was trying to figure out how to set the grouping on a date field by year, month, week, day, hour and so on
Ive used this option but not at runtime, that option is the one available when you click the options... button in the group expert
If you or anyone else could give a clue or something
Ill appreciate it
 
 
Thanks
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 26 Oct 2007 at 7:54am

You should be able to use the same ToText technique that I explained above. 

Year would be: ToText({datefield}, 'yyyy')

Month: ToText({datefield}, 'yyyyMM')

etc.  Look at the Help for ToText to see all of the date formats.  Please note that the format string is case sensitive - month is 'MM' not 'mm'.

-Dell

IP IP Logged
Alexeixx3
Newbie
Newbie
Avatar

Joined: 19 Oct 2007
Location: Mexico
Online Status: Offline
Posts: 3
Quote Alexeixx3 Replybullet Posted: 31 Oct 2007 at 12:21pm
Thanks a lot hilfy
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.055 seconds.