Académique Documents
Professionnel Documents
Culture Documents
108
Open the file from which you want to establish the relation in
one work area.
In another work area, open the file you wish to link to the first
file.
Activate an index file based on the field (or expression) that is
common on both files.
Use the SET RELATION command to establish the link.
Once the link has been established, any movement of the record
pointer in the active file (also known as the parent file) will cause
FoxPro to seek the corresponding record in the related file (also
known as the child file). The nature of such a relationship can be seen
in the example shown in the following paragraphs.
109
110
111
112
113
114
<
<
If FoxPro could not determine the proper linking field, you would
enter the expression into the Expression Builder text box, either by
typing CODE or by selecting the field name from the Field Names list.
Now select the OK button to complete the task.
After you return to the View window, the screen resembles as follows:
115
COMPANY table and watch the STATUS table Browse Change to show
a different group of matching records.
Fig 7.10 Browse result after setting relation between two windows
Notice that the above relation created in many-to-one Relation, i.e.
the parent (COMPANY) can have many record that uses a particular
company CODE.
116
Now return to the View window, with the COMAPNY & STATUS table
open and a relation set on the CODE field between the COMPANY
table & STATUS table. Make sure that the COMPANY table is the
currently selected table.
Notice that after you select the COMPANY table, in the View window,
the 1-to-Many push button is active. Select this option now by
pressing T, or by clicking the button with the mouse. This brings the
1-To-Many dialog box.
117
Make sure that COMAPNY is the currently selected table. Activate the
Command window and type the following command.
BROWSE FIELDS CODE, COMPANY, STATUS.STATUS, STATUS.LIMIT
Press Enter to execute the command.
As you see the Browse window now treats both tables as if they are one
table. For each record in the controlling (parent ) file, additional
entries are shown until all the child records are displayed on-screen.
( To distinguish between the entries that belong to different parent
records, these additional entries use record blocks shaded with
diamond symbols instead of repeating the information in the parent
table's fields.)
118
create a new query. When FoxPro prompts you for a file, select the
COMPANY.DBF table.
You now have a query with the COMPANY table open. Now try to add
STATUS.DBF in tables. Because you want to relate the COMPANY
table to the STATUS table, you have to add the STATUS table and join
them on their common CODE number (CODE) field. Once again, the
RQBE recognizes this relationship so you simply have to select OK in
the Join Condition dialog box.
119
Now Return to the RQBE screen. Click Do Query now, your output
should look like that shown in figure.