Hi Rimantas,
I'm doing exactly what you ask. I have the same problem: a table with clients(Id PK) and a table with TaxForms ( TaxId, Period, ClientID ). I have to show a browse with all the forms for a given Tax and Period... but the browse should be ordererd by ClientId OR Clients->ClientName. So I build a new pair of temporary indexes using FOR ... WHILE to make them faster. Following the piece of code.
Select M303
Set Relation To Field->CodEmp Into Empresas
// Index On Field->CodEmp Tag 'TCodEmp' For Field->Ejercicio == cAnio Temporary
ordCondSet( "Field->Ejercicio == '"+cAnio+"'.and. Field->Periodo == '"+cPeriodo+"'", &( "{|| Field->Ejercicio == '"+cAnio+"'.and. Field->Periodo == '"+cPeriodo+"'}"),,,,, RECNO(),,,,,,,,,,, .T.,, )
ordCreate(, "TCodEmp", "Field->CodEmp", {||Field->CodEmp}, )
// Index On Field->Empresas->Empresa Tag 'TEmpresa' For Field->Ejercicio == cAnio Temporary
ordCondSet( "Field->Ejercicio == '"+cAnio+"'.and. Field->Periodo == '"+cPeriodo+"'", &( "{|| Field->Ejercicio == '"+cAnio+"'.and. Field->Periodo == '"+cPeriodo+"'}"),,,,, RECNO(),,,,,,,,,,, .T.,, )
ordCreate(, "TEmpresa", "Empresas->Empresa", {||Empresas->Empresa}, )
Go Top
This works OK. I have used the functional form of INDEX because I replaced the variable part of the filter expresion with constants.
Hope this helps,
Carlos.