PRB: Trigger Fails with One-to-Many Form Wizard and RI Builder (137278)
The information in this article applies to:
- Microsoft Visual FoxPro for Windows 3.0
This article was previously published under Q137278 SYMPTOMS
The following sequence of events results in this error:
Failed to update table: Trigger Failed
Sequence of Events Leading to Error- Use the Referential Integrity (RI) Builder to set the Insert Trigger of
the child table to Restrict.
- Use the One-to-Many Form Wizard to create a form.
- Run the form, and click Add, then click Add Record to Both in the Add
Record dialog box, and save the form.
CAUSE
When Visual FoxPro opens the tables, it opens the parent first and then the
child. The Parent table is opened in work area one. When the child table is
opened, the parent is moved to work area two, and the child is opened in
work area one.
The UpdateRows method in Wizstyle.vcx handles updating the tables. It uses
the AUSED() function to place the names of the tables into an array and a
For loop to cycle through each table and append the new record. Because the
record is appended to the child table first (because of its order in the
array and work area), the trigger cannot find a matching record in the
parent, so it fails. If the the record was appended to the parent table
first, the problem would not occur.
RESOLUTION
You can modify the code in the UpdateRows method of the txtbtns class of
Wizstyle.vcx. Find the line that reads:
FOR I = 1 TO m.nTablesUsed
Change it to this:
FOR I = m.nTablesUsed TO 1 STEP -1
This causes the record to be appended to the parent table first, so the
Insert trigger will see a corresponding record in the parent when it
updates the child.
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 2/12/2000 |
---|
Keywords: | KB137278 |
---|
|