>I have a form that accepts a parameter that is used in a select sql statement that in turn loads a grid. ie:
>
>Form Init:
>
>PARAMETERS pcGuestNumber
>LOCAL lmAlias
>
>lmAlias = alias()
>
>this.grid1.recordsource = ''
>select * from bills;
>where gnum = &pcGuestNumber;
>order by gnum into cursor billcurs
>this.grid1.recordsource = 'billcurs'
>
>if !empty(lmAlias)
> select &lmAlias
>endif
>
>The error is "Cannot find variable pcGuestNumber" but if I comment out
>the line that sets the recordsource of the grid, there is no error and the cursor is available just like it should be. gnum is a regular index, not unique. The recordsourcetype is set to alias. Do I have to index the cursor after the query? It seems to me the cursor should already be ordered and should not require an index to populate the grid? I've run into this before but I still don't understand this error.
>
>Eric K.
Try creating a custom property in your form called cGuestNumber(or whatever), and setting the value of YourFORM.cGuestNumber to pcGuestNumber and then running the SQL. By the way, set .RecordSourceType = 0 where you have .RecordSource='', and before assigning the cursor as a grid source, set .RecordSourceType=1.
You do not need to index it for ordering. You may need a check (_TALLY) to ensure that your grid gets populated with a few records!
That is to say,
.RecordSourceType = 0
.RecordSource = ''
SELECT ...;
FROM ..;
WHERE gnum = .cGuestNumber ;
ORDER BY ...;
INTO CURSOR ...;
IF _TALLY > 0
.RecordSourceType = 1
.RecordSource = 'BILLCURS'
ELSE
*-- Some message
ENDIF
Sanjay
Sanjay Kapoor
Relatively speaking is a conversation with Einstein