>Hello all
>
>i have a form, table for the form is provided at runtime, i have a combo box with distinct values, and depending upon the value the grid is populated,
>
>the problem now is the recordsource of the grid is a view, since the form will have a different table at run time, how to change the view, or how to create a updatable view dynamically.
>
>txs
Akhan,
You mean how to change the recordsource of grid ?
If grid is readonly you might simply make its recordsource an SQL.
If not :
with myGrid
.Recordsource = '' && Assuming you want to keep format
.Recordsource = 'NewCursorTableViewName'
endwith
Create an updatable view on the fly (I don't think you'd ever need this) :
*form custom property holding name of view - assuming a DBC is open or you might create that too
thisform.TempViewName = sys(2015)
create SQL view (thisform.TempViewName) as ;
select ....
DBSetProp(thisform.TempViewName, 'View', 'SendUpdates', .T.)
DBSetProp(thisform.TempViewName, 'View', 'Tables', DBC()+'!Tablename') &&List
* Fields
DBSetProp(thisform.TempViewName+'.myField', 'Field', 'KeyField', .T.)
DBSetProp(thisform.TempViewName+'.myField', 'Field', 'Updatable', .F.)
DBSetProp(thisform.TempViewName+'.myField', 'Field', 'UpdateName', DBC()+'!TableName.myField')
DBSetProp(thisform.TempViewName+'.myField', 'Field', 'DataType', lcType)
*...
You could get how this syntax would be by creating a view in designer and running gendbc against you database.
-If you make it as if it were a remoteview then syntax is easier.
-If you'd do this repeatedly for same view layout I'd get a designer output where I name the view to a special name like '_MYTEMPLATE_' and save it to a file :
lcTemp=sys(2015)+'.prg'
strtran(FileToStr('mytemplate.prg'),'_MYTEMPLATE_',thisform.TempViewName, ;
lcTemp)
compile (lcTemp)
do (lcTemp)
erase (juststem(lcTemp)+'.*')
-Form.destroy
drop view (this.TempViewName)
Or what you mean is this grid uses updatable view to view/edit records instead of a view directly using the table(s) might be a much easier solution.
PS: Though I use grids a lot I rarely use views with them despite docs and majority suggests it that way (I do too but not for myself:). It's mainly personal preference depending I was doing that stuff before views existed in fox (browse not grid of course).
Cetin