Microsoft KB Archive/139524

= How to Create a Builder to Add Tables to the Data Environment =

Article ID: 139524

Article Last Modified on 2/10/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q139524



SUMMARY
Often several tables must be added to the data environment of a form. It is possible to create a builder that allows you to select and add multiple tables at one time.



MORE INFORMATION
The following steps create a builder that allows the developer to select a single .dbc file. Then a form appears containing two multiple-select list boxes. The first list contains the names of the tables in the .dbc file, and the second list contains the names of the views in the .dbc file.

When you click the Add to DE button, each table selected is added to the data environment of the form.

Steps to Create Builder
 Create a new form.  Add the following new properties to the form: dbcName dbcTables[1] dbcViews[1] gaDataEnvironment[1]   Add the following code to the Init event of the form: *  Obtain an object reference to the data environment of the form in   *   the Forms Designer =ASELOBJ(ThisForm.gaDataEnvironment,2)

*  Ask the user which .dbc file should be used, cancel builder if none ThisForm.dbcname = GETFILE("DBC", "Select Database", "Open") IF EMPTY(thisForm.dbcName) RETURN .F.  ENDIF

* Populate arrays with the names of tables and views OPEN DATABASE (thisForm.DBCName) lnTables=ADBOBJECTS(thisform.dbcTables,"TABLE") ThisForm.LstTables.Requery IF lnTables = 0 thisform.dbcTables(1,1) = "No Tables found" thisform.LstTables.Enabled = .F.  ENDIF lnViews=ADBOBJECTS(thisform.dbcViews,"VIEW") ThisForm.LstViews.Requery IF lnViews = 0 thisform.dbcViews(1,1) = "No Views found" thisform.LstViews.Enabled = .F.  ENDIF   Add two list boxes to the form. Set the following properties for the first list box: MultiSelect  = .T.   Name          = LstTables RowSourceType = 5 (Array) RowSource    = Thisform.dbcTables   Set the following properties for the second list box. MultiSelect  = .T.   Name          = LstViews RowSourceType = 5 (Array) RowSource    = Thisform.dbcViews   Add a command button to the form. Change the caption to Add to DE. Place the following code in its Click event: FOR iCnt = 1 TO THISForm.LstTables.ListCount IF ThisForm.LstTables.Selected(iCnt) lcName = PROPER(ThisForm.LstTables.ListItem(iCnt)) IF TYPE('ThisForm.aDataEnvironment(1).&lcname') != 'O'        ThisForm.gaDataEnvironment(1).AddObject(lcname, "Cursor") WITH ThisForm.gaDataEnvironment(1).&lcname. .Alias = lcname .CursorSource = lcname .Database = ThisForm.dbcName ENDWITH ENDIF ENDIF ENDFOR FOR iCnt = 1 TO THISForm.LstViews.ListCount IF ThisForm.LstViews.Selected(iCnt) lcName = PROPER(ThisForm.LstViews.ListItem(iCnt)) IF TYPE('ThisForm.aDataEnvironment(1).&lcname') != 'O'        ThisForm.gaDataEnvironment(1).AddObject(lcname, "Cursor") WITH ThisForm.gaDataEnvironment(1).&lcname. .Alias = lcname .CursorSource = lcname .Database = ThisForm.dbcName ENDWITH ENDIF ENDIF ENDFOR ThisForm.Release   Add a Cancel command button that contains the following line of code in its Click event: ThisForm.Release </li> Save the form as Deblder.</li> Register the builder by using one of the methods described in the Visual FoxPro Help file or by adding a record to the Builder.dbf file.</li></ol>

Because the builder is based on a form, it can easily be customized. You may want your builder to include several common sets of data.

Additional query words: VFoxWin

Keywords: kbcode KB139524

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.