troubleshooting Question

Grouping and sorting from VB 6 app

Avatar of ROTRTechTeam
ROTRTechTeam asked on
Crystal Reports
6 Comments1 Solution289 ViewsLast Modified:
I have a report in a VB 6 app that I want to dynamically select the grouping and then sort the details within the group on another field that is in the report.  Thus, I've created a formula field that is called @Grouping and another called SortFormula.  I have the following code in VB:

    If optSort(0).Value Then
        Report.FormulaFields(1).Text = "{rep_RestaurantTouchReport;1.RestaurantName}"
        Report.FormulaFields(3).Text = "{rep_RestaurantTouchReport;1.RestaurantName}"
    ElseIf optSort(1).Value Then
        Report.FormulaFields(1).Text = "{rep_RestaurantTouchReport;1.TouchType}"
        Report.FormulaFields(3).Text = "{rep_RestaurantTouchReport;1.TouchType}"
    ElseIf optSort(2).Value Then
        Report.FormulaFields(1).Text = "{rep_RestaurantTouchReport;1.EnteredBy}"
        Report.FormulaFields(3).Text = "{rep_RestaurantTouchReport;1.EnteredBy}"
    Else
        Report.FormulaFields(1).Text = "{rep_RestaurantTouchReport;1.touchdate}"
        Report.FormulaFields(3).Text = "{rep_RestaurantTouchReport;1.touchdate}"
    End If
   
    If optDirection(0).Value Then
        Report.RecordSortFields(1).SortDirection = crAscendingOrder
    Else
        Report.RecordSortFields(1).SortDirection = crDescendingOrder
    End If
 
This works to enable the dynamic select of the groupings.  Thus, if I pick "sorty by Entered By" it will group by EnteredBy field and if I select "sort by Restaurant Name" it will group by the RestaurantName field.  However, what I really want is this:

If the sort is by anything other than EnteredBy, I want to group by the field being sorted and then sort the details by EnteredBy.  If the sort is EnteredBy, I want to group by EnteredBy and then sort the details by RestaurantName field.  

So, I changed the above code as follows:

    If optSort(0).Value Then
        Report.FormulaFields(1).Text = "{rep_RestaurantTouchReport;1.RestaurantName}"
        Report.FormulaFields(3).Text = "{rep_RestaurantTouchReport;1.EnteredBy}"
    ElseIf optSort(1).Value Then
        Report.FormulaFields(1).Text = "{rep_RestaurantTouchReport;1.TouchType}"
        Report.FormulaFields(3).Text = "{rep_RestaurantTouchReport;1.EnteredBy}"
    ElseIf optSort(2).Value Then
        Report.FormulaFields(1).Text = "{rep_RestaurantTouchReport;1.EnteredBy}"
        Report.FormulaFields(3).Text = "{rep_RestaurantTouchReport;1.RestaurantName}"
    Else
        Report.FormulaFields(1).Text = "{rep_RestaurantTouchReport;1.touchdate}"
        Report.FormulaFields(3).Text = "{rep_RestaurantTouchReport;1.EnteredBy}"
    End If
   
    If optDirection(0).Value Then
        Report.RecordSortFields(1).SortDirection = crAscendingOrder
    Else
        Report.RecordSortFields(1).SortDirection = crDescendingOrder
    End If

What happens is that the grouping is no longer dynamic.  It is always by EnteredBy.  What am I doing wrong?

Thanks!

Mike
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros