Quote: // So I put it in OnElementExit. It seems to work perfectly there.
Mark,
Well... not so perfectly.
Within the subform: if I down arrow to a new line (blank record) and up arrow without making any changes, that blank record disappears (programming should be filling System ID upon exiting the element, but it's not). Yet, when I save the main record with Ctrl-10 or F10, and return with F9, that unwanted subrecord is there with the System ID element filled.
Now forget all that.

Here's the root of the problem: after some testing, I found that the On Element Exit event is not firing every time I exit an element. If I click on an element (highlighting it in gray), then click on another element (same gray highlight), no event occurs until I click on a different subrecord or the main form. In the case of the main form, it fires TWO times. (Erika posted a message indicating that WriteLn may cause multiple firings, so I tested this without using it. I added one "*" to a text field at each firing.)
The only way to activate the element exit event while staying on the same subrecord, is to click twice on one element (changing the background to white), and then click twice on another element. The event only fires when the 2nd element's background turns white, rather than when you exit the 1st element.
I understand that being
highlighted in gray maybe wasn't intended to be considered having "entered" an element, but leaving that element after having a white background should definitely constitute an element exit. Yet, you need to begin editing another element, making it's background white before the exit event of the previous element will fire.
Does that make sense?
Also, if you edit a subform element, then click straight to a main form element, your edits are lost. Other methods of leaving the element (e.g. F10, Ctrl-F10, ArrowDown, Tab) retain them properly.
FYI:
To avoid confusion, I removed all other programming in the subform layout and the main layout to be sure I wasn't getting strange results due to other events interfering.