Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How sort report based upon parm?

Posted on 2002-04-08
6
Medium Priority
?
412 Views
Last Modified: 2010-08-05
Basics:  vb6 sp5, cr8.0, W/2000.

I have written a Visual Basic program that calls a Crystal Report and passes various parameters to it.  One of these parms is the sort parm.  In CR I want the report to sort in one of three ways based upon the passed parm from vb.

I thought that creating a formula that would interogate the parm and point to the field to be sorted would work.  But it gives me errors.  

For example, here is the code in a formula in CR that uses the Select Case method:

Select Case {?mSort_Opt_Parm}
Case "Invoice #"
formula = {Reporting.Inv_No}
Case "Invoice Date"
formula = {Reporting.Inv_Date}
Case "Delivery Date"
formula = {Reporting.Del_Date_Sort}
End Select

This code generates an error.  I swapped out the Select Case with an If, ElseIf etc. code and it does not work either.  Here is that code:

If {?mSort_Opt_Parm} = "Invoice #" Then {Reporting.Inv_No}
ElseIf {?mSort_Opt_Parm} = "Invoice Date" Then {Reporting.Inv_Date}
Else {Reporting.Del_Date_Sort}

I am trying to come up with a formula that points to the field I want the report to sort on, i.e. {Reporting.Inv_No}.  With this type of field, I would only have to add it to the sort dialog box and the report would supposedly sort in the correct sequence based upon the passed parm.  Should I be doing this differently?

Question:  How do I sort a report based upon a passed parameter?

Thanks for the help.
0
Comment
Question by:EYoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 6928540
How are you calling the report from VB.  CR provides a sort field array to use.

Here is the code I use

Public Sub preview_Report_from_View_with_Sort(txt_Report_File_Name As String, _
                                                                        txt_Record_Selection_Formula As String, _
                                                                        txt_Sort_Fields() As String, _
                                                                        int_Sort_Field_Count As Integer)
Dim i As Integer
Dim rpt_title As String
    cr_Generic_Report.WindowTitle = rpt_title

    cr_Generic_Report.ReportFileName = txt_Report_File_Name
    cr_Generic_Report.ReplaceSelectionFormula txt_Record_Selection_Formula
    For i = 0 To int_Sort_Field_Count - 1
        cr_Generic_Report.SortFields(i) = txt_Sort_Fields(i)
    Next i
    cr_Generic_Report.WindowState = crptMaximized
    cr_Generic_Report.Destination = crptToWindow
    cr_Generic_Report.WindowShowCloseBtn = True
    cr_Generic_Report.Action = 1
    cr_Generic_Report.Reset
   
End Sub

The sort fields are strings like {view_rpt_basic.student_id}

If you need more information let me know.
good luck

mlmcc
0
 
LVL 7

Author Comment

by:EYoung
ID: 6928821
mlmcc,

Here is the code I use in VB to call the report:


Private Sub Form_Activate()
    Set Report = New dsrDetail_and_Summary
   
    Report.EnableParameterPrompting = False

    Report.ParameterFields(1).AddCurrentValue mTeam_No_Parm
    Report.ParameterFields(2).AddCurrentValue mTeam_Name_Parm

    If mTeam_No_Parm <> 0 Then
         Report.RecordSelectionFormula = "{Reporting.mKey} = '" & mKey2 & "'"
    End If

    Screen.MousePointer = vbHourglass
    CRViewer1.ReportSource = Report
    CRViewer1.DisplayTabs = False
    CRViewer1.DisplayToolbar = True
    CRViewer1.EnableGroupTree = False
    CRViewer1.EnableExportButton = True
    CRViewer1.ViewReport

    Screen.MousePointer = vbDefault
End Sub

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

The report has two levels of grouping and then one of three fields make up the third sort field.  For example, the sort fields could be Group1, Group2, Invoice_No.  Or the sort fields could be Group1, Group2, Invoice_Date.

Would I add the .SortFields(i) as follows:

CRViewer1.SortFields(1) = Group1
CRViewer1.SortFields(2) = Group2
CRViewer1.SortFields(3) = Invoice_No

Thnaks for the help.
0
 
LVL 7

Author Comment

by:EYoung
ID: 6929060
I tried doing the example above and it did not have any effect on the sort sequence of the report.

Would appreciate any help.  Thanks.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Author Comment

by:EYoung
ID: 6929075
Oops, I should have said I tried:

Report.ReportSortFields(1) = ...
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 100 total points
ID: 6929237
0
 
LVL 7

Author Comment

by:EYoung
ID: 6929857
Thanks for the help.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question