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

x
?
Solved

Crystal Reports 7 RecordSortFields

Posted on 2000-02-23
2
Medium Priority
?
1,808 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 280 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

660 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