--snip--
>>SELECT parent.company, parent.address, child.name, child.phone;
>> FROM parent, child;
>> WHERE parent.IDCODE = child.IDCODE;
>> INTO cursor VUTEMP;
>> ORDER by COMPANY
>
>Thanks for the tip Barbara. I now have a form with the parent table's fields and a grid containing the child rows.
>If you have a moment, I have a few more questions:-
Martin, it's either your questions or dinner, so of COURSE I have time :-)
>Am I right in thinking that the SQL you gave as an example is that generated by the view definition? Or do you mean I should be hardcoding the SQL statement somewhere?
Either way is fine. I use a View for any SQL that is going to be used in more than one place. For example on 2 forms and a report. If it's only used one place, I usually just pop the SQL onto the form. This is personal preference.
>How do I add records to the child table? The Tastrade example used a right-click popup-menu which ran some code to append a blank child record, set it's key to that of the parent's primary, and then setfocus to the grid line.
>
>If I try this with the parent/child view, APPEND BLANK is going to insert a row to the parent table as well as the child table.
>After setting the primary key of this blank row, the TABLEUPDATE fails with error 1884 - duplicate primary key.
>
>Is there a way I can use this combined view to create new primary table rows AND/OR new child table rows?
You add the records to the main tables and then ReQuery() the view. Just the opposite of the way you were trying. When a user presses ADD CHILD button, you'd store the parent ID, select CHILD, APPEND BLANK (or INSERT) a new CHILD record with the child's uniqueid, and the parent's primary id as the child's link.
Next, do a tableupdate() to store the new record to disk.
Finally, do a ReQuery on the View, so the new record is included, locate the new record (save the uniqueid you entered earlier) and do a grid refresh.
It sounds a LOT more difficult than it is.
HTH
Barbara