Results 1 to 8 of 8

Thread: Sorting Crystal Report from VB

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    Sunny Scottsdale Arizona
    Posts
    254

    Sorting Crystal Report from VB

    I would like to give users the ability to sort a Crystal Rpt at run-time. Report is based off of ADO connection to MS Access database.

    The user should be able to sort Ascending or Descending by either deal_name or bid_price.

    Anyone out there a crystal sorting guru?

    thx

  2. #2
    Lively Member Harvester's Avatar
    Join Date
    May 2002
    Location
    God's Country
    Posts
    124

    Sorting

    If you're using the Crystal objects the report object has a collection called SortFields (i.e. Report.SortFields)

    You can add or remove sort fields through that.

    Report.SortFields.Add(<Your Field Object>)


    If you're using the Crystal API look into a function called PESetNthSortField

  3. #3
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295
    try something like this

    Code:
    CystalReport.GroupSortFields(0) = "+{Count of rptCustStatement.RecDate}"
    Craig Johnstone, MCP,CNA

    VB 6,SQL,Lotus Notes,Crystal Reports 7,8

    http://www.cajsoft.co.uk/downloads.htm

  4. #4
    New Member
    Join Date
    Apr 2017
    Posts
    2

    Re: Sorting Crystal Report from VB

    Quote Originally Posted by cajsoft View Post
    try something like this

    Code:
    CystalReport.GroupSortFields(0) = "+{Count of rptCustStatement.RecDate}"
    The code should probably be more like
    CystalReport.RecordSortFields(0) = "+{TableName.FieldName}"

    The group sort fields are used for sorting GROUPS while the Record Sort Fields are for sorting records within any groups (if groups exist) or sorting the records if there is no grouping.

    However the syntax for this also depends on WHICH version of Crystal Reports you are using and whether you are using the VBX (in VB3) or OCX (in VB6) or using the API using DLL calls (in either Vb3 or VB6) or using the object model (in VB6). In Vb.Net it works differently again.

    I'm just trying to work this out for VB6 using the object model which means that you have to ADD, DELETE or COUNT sort fields.
    So lets say your report already has a sort field in it.
    Then you can

    Dim CRWApp As New CRAXDRT.Application, CRWReport As CRAXDRT.Report

    Set CRWReport = CRWApp.OpenReport(ReportName)
    CRWReport.RecordSortFields.Add SortField, SortOrder

    But SortField is not a field name but a field definition object and I can't quite work that one out yet.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2002
    Location
    Sunny Scottsdale Arizona
    Posts
    254
    cajsoft'

    tried your code and got 'Subscript out of Range' error.

    CystalReport.GroupSortFields(0) = "+{Count of rptCustStatement.RecDate}"

    Why do I need to take a count of the table fields?

    My code looks like this:

    '--------Encapslulated code opens cr report--------
    Dim Report As New rptLPCAvgOfBid

    If cboSort.Text = "A - Deal" Then
    Report.GroupSortFields(0) = "+{Count of Report.loan_desc}"
    End If

    frmRptView.CRViewer1.ReportSource = Report
    frmRptView.Show
    frmRptView.CRViewer1.ViewReport
    '-------------------------------------------------

  6. #6
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295
    Sorry, I think I'm leading you in the wrong direction.

    Found this on Crystal Support site


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

    How can you change the order of groups at runtime using the Crystal ActiveX (OCX) Control?

    For example, if a group is based on a country field, and the report is designed with countries grouped in ascending order (A to Z), how can you change the grouping of countries to descending order (Z to A) at runtime?

    Solution

    Use the 'GroupCondition' property to change the order of groups at runtime.

    Here is a code sample which changes the group order of the first grouping level (based on the country field) to descending order:

    CrystalReport1.GroupCondition(0) = "GROUP1;{Customer.Country};ANYCHANGE;D"

    There are four values that the GroupCondition property requires:

    · 'GROUP1' refers to the first grouping level in the report.

    · '{Customer.Country}' refers to the field that the group is based on.

    · 'ANYCHANGE' refers to the condition that triggers the grouping. If the group is not based on a Date or Boolean field, then this value will be ANYCHANGE.

    · 'D' refers to the sort direction (A for ascending, D for descending)

    For more information on the 'GroupCondition' property, refer to the Crystal Reports online Developer's help installed with Crystal Reports (Developr.hlp).

    NOTE:=====

    The 'GroupSortFields' property will only sort the records within a group itself. It does not affect the order of groups in a report.
    Craig Johnstone, MCP,CNA

    VB 6,SQL,Lotus Notes,Crystal Reports 7,8

    http://www.cajsoft.co.uk/downloads.htm

  7. #7
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,834

    Re: Sorting Crystal Report from VB

    Can't you just sort the data coming from the database instead of once it is back?
    Please remember next time...elections matter!

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Sorting Crystal Report from VB

    This may be some kind of gravedig record. I don't even recognize any of the original people in this thread, which may be because the thread was created only about a month after I joined, which was 15 years back. It would be better to start a new thread than try to extend this one. If you'd like, I'd be willing to split this out to a new thread, but since you referenced an earlier post, it would require a bit of editing to make it reasonable. Just starting a new thread would be the best route.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width