The information in this article applies to:
- Microsoft FoxPro for Windows, versions 2.5 and 2.5a
- Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a
- Microsoft FoxPro for Macintosh, versions 2.5x, 2.6, 2.6a
SUMMARY
This procedure below describes how to coordinate a parent data window with
a child Browse window using the power tools. The screen and its controls
are designed in such a way that as you move through the parent database,
the parent's data is updated and so is the Browse window that displays the
related records in the child database. In this example, the CUSTOMER and
INVOICES databases are used to establish a one-to-many relationship. Both
the CUSTOMER and INVOICES databases are located in the FoxPro TUTORIAL
subdirectory.
MORE INFORMATION
- Use the View window to set up a one-to-many relationship between the
CUSTOMER (parent) database and the INVOICES (child) database. Select
the parent database by clicking it.
- Create a quick screen.
- Save the environment and add the following code into the following
code options in the Screen Layout dialog box:
Setup Code
----------
DEFINE WINDOW child FROM 17,1 to 24,70 PANEL;
FLOAT GROW
ACTIVATE WINDOW child
SELECT INVOICES
BROWSE IN WINDOW child NOWAIT SAVE NOMODIFY LAST
SELECT CUSTOMER
Cleanup Code
------------
RELEASE WINDOW child
Activate Code
-------------
SELECT CUSTOMER
- If you are using FoxPro for MS-DOS, choose Layout from the Screen
menu, then set the screen type to Window. (In FoxPro for Windows, this
step is unnecessary because the screen is a window by default.)
- Resize the window so that it fits around the fields without
leaving a lot of empty space.
- Save the screen as TEST.SCX and then close it.
- From the File menu, choose Open, and set the file type to Screen.
NOTE: Before proceeding with this next step, make a backup of the
CONTROL3.SCX and CONTROL3.SCT files (if you are using FoxPro for
MS-DOS) or the CONTROL1.SCX and CONTROL1.SCT files (if you are
using FoxPro for Windows).
- In FoxPro for MS-DOS, select CONTROL3.SCX (located in your FoxPro
TUTORIAL subdirectory) and then choose Open. In FoxPro for
Windows, select CONTROL1.SCX (located in your FoxPro
SAMPLE\ORGANIZE\SCREENS subdirectory) and then choose Open.
- Double-click one of the push buttons on the screen and select the
Valid code snippet check box.
- The Valid code snippet is shown below. Modify the code by adding
the two designated lines. The code below is from FoxPro for MS-DOS
and looks slightly different in FoxPro for Windows.
SET SKIP TO && Add this line
DO CASE
CASE act2 = 1
GO TOP
CASE act2 = 2
SKIP -1
IF BOF()
GO TOP
ENDIF
CASE act2 = 3
SKIP 1
IF EOF()
GO BOTTOM
ENDIF
CASE act2 = 4
GO BOTTOM
CASE act2 = 5
APPEND BLANK
CASE act2 = 6
CLEAR READ
ENDCASE
SET SKIP TO invoices && This line is optional.
SHOW GETS
RETURN 0
- Save the screen as MYCONTRL.SCX.
- From the File menu, choose Open, and then set the type to Screen.
- Select TEST.SCX and then choose Open.
- From the Program menu, choose Generate.
- Choose Add.
- Select MYCONTRL.SCX and then choose OK.
- Choose Arrange and arrange the two screens to be toward the top of
the window. Try not to overlap the screens.
- In FoxPro for MS-DOS, choose Save from the Arrange menu. In FoxPro
for Windows, choose OK.
- Choose Generate.
- In the Command window, issue the following command:
DO test.spr
Notice the three screens come up. Choosing Next from the control screen
displays the updated parent screen. The related records of the child in the
browse are also updated.
NOTE: You can also use FOXAPP to relate two tables and accomplish the same
goal.
|