Solved

Crystal Reports 7 RecordSortFields

Posted on 2000-02-23
2
1,792 Views
Last Modified: 2008-02-20
I'm using VB 6 and Crystal Reports 7.  I'm trying to set the report sort order at runtime based on user input.  
ie, If they select sort by Manufacturer Name then I'm trying to use the following code:

oCR.RecordSortFields(0) = "+{Return_ttx.MfgName}"

where oCR is a crystal report designer object

I get an error saying subscript is out of range.  Any suggestions on how to correct this?  Is there a better way to set the sort order at run time?
0
Comment
Question by:CrazyFox
[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
2 Comments
 
LVL 1

Accepted Solution

by:
sramkris earned 70 total points
ID: 2551369
Hi I hope this article helps you in sorting data as per your requirement

This article demonstrates how a report's sorting can be modified at runtime, using the Report Designer Component's (RDC) object model.


Solution

There are 2 scenarios in which a report's grouping can be modified at runtime.

1. Changing the existing sort's condition field.
2. Adding a new sort to the report.

NOTE:
- All the samples are based on the sample database, XTREME.MDB, which is installed by Seagate Crystal Reports.

1. Changing the Existing Sort's Condition Field

For this scenario, a report is created which is currently sorted on the Customer Name field (Ex. {Customer.Customer Name}). To change the condition field for the existing field at runtime, the following code can be used.

'General Declarations
Dim Report As New CrystalReport1
Dim crxDatabaseField As craxdrt.DatabaseFieldDefinition

Private Sub Form_Load()

'Currently the sort is based on the Customer Name field and the application
'is to change it to the 'Last Year's Sale's' field. This field must be present
'on the report. Basically, accessing the first table to get the 8th field
Set crxDatabaseField = Report.Database.Tables.Item(1).Fields.Item(8)

'There is only one Sort on this report so we will access the first item of the
'SortFields collection and set the field to the 'Last Year's Sale's' field
Report.RecordSortFields.Item(1).Field = crxDatabaseField

CRViewer1.ReportSource = Report
CRViewer1.ViewReport

End Sub

2. Adding a New SortField to a Report

'General Declarations
Dim Report As New CrystalReport1
Dim crxDatabaseField As craxdrt.DatabaseFieldDefinition

Private Sub Form_Load()

'Currently there is no sort in this Report. To add the Sort Field Customer Name
'the application must first get the {Customer.Customer Name} field from the Customer Table. Basically, 'accessing the first table to get the 2nd field
Set crpDatabaseField = Report.Database.Tables.Item(1).Fields.Item(2)

'Now add the field to the SortFields Collection and set the Sort Order to ascending.
Report.RecordSortFields.Add crxDatabaseField, crAscendingOrder

'Note. If the SortField is added while the Report is viewing the Viewer will have to be refreshed
'before the new sort will be active. This can be done by clicking the Refresh button in the Smart 'Viewer or Refreshing the viewer through code. Ex:
'CRViewer1.Refresh

CRViewer1.ReportSource = Report
CRViewer1.ViewReport

End Sub
0
 

Author Comment

by:CrazyFox
ID: 2551438
sramkris,

Thanks a million, that worked like a charm.  I had no idea you had to use a CRAXDRT.DatabaseFieldDefinition to get that to work.  

Thanks again.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month7 days, 15 hours left to enroll

617 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