Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort Fields from VB 1

Status
Not open for further replies.

larrysj

Programmer
Oct 21, 2001
4
0
0
US
Try as I might, I cannot figure out how to set the sort fields on my report from my VB6 app. Please help.
 
Got this from Crystal Decisions:

Here is sample code using the Add method with a Database field:

Syntax:

Sub Add(pFieldDefinition As IFieldDefinition, SortDirection As CRSortDirection)

- The first parameter only accepts a database field as specified by its index.
- The second specifies whether you want to sort in Ascending, Descending, Specified or Original order.

-Sample code
Dim Report As New CrystalReport1
Dim crxDatabaseFieldDefinitions As CRAXDRT.DatabaseFieldDefinitions
Dim crxDatabaseFieldDefinition As CRAXDRT.DatabaseFieldDefinition


Private Sub Form_Load()
Screen.MousePointer = vbHourglass
'finds the first table in the report
Set crxDatabaseFieldDefinitions= Report.Database.Tables.Item(1).Fields
'sets the DatabaseFieldDefinition to the third field in the fields collection.
Set crxDatabaseFieldDefinition= crxDatabaseFieldDefinitions.Item(3)

Report.RecordSortFields.Add crxDatabaseFieldDefinition, crDescendingOrder

CRViewer1.ReportSource = Report
CRViewer1.ViewReport
Screen.MousePointer = vbDefault

End Sub



Hope this helps!
 
Of course there are 4 different ways depending on your integration method. If you don't know your method, see the FAQ in the general forum on "Questions should include.." Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
Hi mmaz
I tried your sample code but when i try to run it, it gives me the following error:

Runtime Error '-2147467261 (80004003)'
Method 'Database' of object 'IReport' failed

Any ideas? i would appreciate your response.
 
Here you go, my code:

Dim Report As New CRAXDRT.Report
Dim crxDatabaseFieldDefinitions As CRAXDRT.DatabaseFieldDefinitions
Dim crxDatabaseFieldDefinition As CRAXDRT.DatabaseFieldDefinition

Private Sub Form_Load()
Screen.MousePointer = vbHourglass
' Fails on the below line
Set crxDatabaseFieldDefinitions = Report.Database.Tables.Item(1).Fields
Set crxDatabaseFieldDefinition = crxDatabaseFieldDefinitions.Item(3)
Report.RecordSortFields.Add crxDatabaseFieldDefinition, crDescendingOrder
frmViewer.CRViewer.ReportSource = Report
frmViewer.CRViewer.ViewReport
Screen.MousePointer = vbDefault
End Sub

thanks,
 
How is your report connected to the db?
Which db and CR version are you using?
 
I am using Crystal Reports 8.5 Professional and SQL Server Database. I am not sure what do you mean by "how is the report connected to database"?

Please let me know
 
ODBC, OLEDB, Database File, TTX File?
 
I am afraid that 8.5 professional doesn't integrate with VB. You need 8.5 developer. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
I can add to the first post of mmaz that this method also works with SummaryFieldDefinition and FormulaFieldDefinition...

This helped me a lot! Thx!!

Mim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top