' VB 2005/Crystal XI 2008
' my reports has three fields Lastname, Firstname, address
' in my report I have added the address as my default sort field
' the following code allows me to change the sort field to another field.
' if I try to sort on address I get an error "sort field already exists.
' if I remove the default sort filed my code gives me an error.
' my problem now is how can I sort on multiple fields ????
Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim sDatabaseFile As String = "c:\Data\DatabaseFile.mdb"
Dim sTableName As String = "myTable"
Dim crDatabaseFieldDefinition As CrystalDecisions.CrystalReports.Engine.DatabaseFieldDefinition
crReportDocument.Load("C:\reports\myReport.rpt")
crReportDocument.DataSourceConnections.Item(0).SetConnection(sDatabaseFile, sTableName, False)
crDatabaseFieldDefinition = crReportDocument.Database.Tables.Item(0).Fields.Item("LastName")
crReportDocument.DataDefinition.SortFields.Item(0).Field = crDatabaseFieldDefinition
crReportDocument.DataDefinition.SortFields(0).SortDirection = CrystalDecisions.Shared.SortDirection.DescendingOrder
CrystalReportViewer1.ReportSource = crReportDocument