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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specify Sort Order in VB

Status
Not open for further replies.

JLR1234

Programmer
Jul 23, 2004
20
US
I am new to CR11 and am updating VB6 code that used the CR8 OCX control. Using the OCX, I passed the sort field with the following code:

CR.sortfields(0)="+{orders.CUSTOMER}"

In CR11 I understand that you would use the following code:

dim crxDBField as craxdrt.databasefielddefinition
set crxdbfield=report.database.tables.item(1).fields.item(8)
report.recordsortfields.item(1).field=crxDBField

However, this assumes that you know table 1 ="orders" and field 8="customers". Is there a better way of determining the table and field numbers without cycling through the descriptions at runtime. The sort order is determined at runtime by the end user so it cannot be hard coded in the report.
 
Does "The sort order is determined at runtime by the end user so it cannot be hard coded in the report." mean that it is collected by the VB app, or a Crystal parameter?

If a Crystal parameter is used, then create a formula in Crystal to test what was selected and use it in the Report-Sort, you don't need any VB code:

if {?parm} = "Orders" then
{table.orders}
else
if {?parm} = "Customer" then
{table.customer}
etc...

If it's captured in VB, then substitute your variable in VB for crxDBField.

-k
 
Thank you for your response. It is captured in VB.

However, I don't understand what you mean by "If it's captured in VB, then substitute your variable in VB for crxDBField."


 
I believe you will need to cycle through the table names to determine that Table 1 = "orders". However, once you have that you can use:

set crxdbfield = report.database.tables.item(1).fields.getitembyname("customers")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top