>Hello everybody!
>
>This is my problem: In the click event of a pushbutton included into a form, I create a free table with data recovered from other two tables. My code names this table with current hour, minute and second and creates a variable (lcTableName), i.e.: lcTableName = 142512.dbf(this permit other users to create their own free table). I can see the data of this table perfectly with the BROWSE command. When I refer to the table I always use the macro &lcTableName.
>
>Well, the problem is comming now: I would like to show this data in a GRID posted in a new form. I have tried to create the grid previously with a fixed data structure and sending later as a PARAMETER lcTableName to the new form trying to assign RecordSource = &lcTableName, but it doesn't work.
>
>Probably I should create the grid by programming, but where should I write this code, into the INIT event of the form?. Someone expert in grids could give an example of such code including how to assign a parameter to the RecordSource?
>
>Thanks in advance!
>
>Carlos Fuertes
Carlos,
Before going to Recordsource, I suggest not to use table/cursor names that don't start with a letter or underscore. If those numbers have meaning for you at least precede with an underscore. Else if it's just to provide a unique name then sys(2015) -sys(2015) uses clock and packs the time with advantage it's unique on a given machine even if called within same millisecond- generated values are perfect for both table/cursor and alias names.
BTW if instead of tables if you create a cursor then it's unique to user (ie: both users might create a cursor named myCursor just at the same time, but their copies are unique to themselves - actual tablename is assigned by VFP implicitly).
Next never use macro substitution to use a table/cursor but name expression operator - parentheses. ie:
use &lcCursor && Works in most cases
* if lcCursor = 'my long table name.dbf' above would fail
* or lcCursor = 'c:\my long file name path\short.dbf'
use (lcCursor) && Works always
IOW not just with use command but anywhere where a name is expected use name expression (windownames, tablenames, formnames, select.. from (tablename) etc etc).
Side tip : You can manage a browse like a grid but for now forget I said this.
At last we could come to problem - or not yet ?:)
You can predefine your grid or have it defined on the fly. Predefined grid has the advantage of playing with cosmetics visually and is easier in most cases. For this very basic reason suppose your grid would always have the same number of columns, headers and no extra tricks is needed. Just create a grid (suppose named myGrid) on a form (say myShower) and set columncount, headers for columns, nothing else. Now calling form might have done this :
lcTable1 = 'table1'
lcTable2 = 'table2'
lcCursor = 'myCursor'
select * ;
from (lcTable1) a ;
inner join (lcTable2) b ;
on a.id = b.id ;
where Something ;
into cursor (lcCursor)
do form myShower with lcCursor
Now myShower with grid only needs this 2 lines in its init :
lparameters tcCursorName
this.myGrid.Recordsource = tcCursorName
BTW your pitfall was to use macro in RecordSource assignment.
myTable = 'anothertable'
lcTable = 'myTable'
.RecordSource = 'myTable'
.Recordsoruce = lcTable
are right but this is wrong if your intention is to open myTable :
.Recordsoruce = &lcTable
&& Opens anothertable - or errors if myTable = '..' weren't there
Cetin