If you use commit record to commit the record on the first layout before the script opens the second window, I wouldn't expect you to get this error message. (Clicking the layout background has the same effect as the script step commit record.)
You are entirely correct about this (and I was on the right track - I already had a "Commit Records" in the code). It turns out that the problem I was really facing was one of window focus. I neglected to mention I'm using another layout comprised solely of buttons to do my layout navigation. Each button on this "navigation layout" (which is always visible on the left side of the screen) brings up a different layout to the right. So what was happening is that the moment I clicked on the navigation layout to bring up the 2nd layout, the focus was brought to the navigation layout before the "Commit Records" command was invoked. Then the 2nd layout comes up but the records on the first layout never got "committed", hence the error message. I've devised bit of awkward code that when a button on the navigation layout is clicked now that it issues a "Select window" command for the 1st layout and commits the records before bringing up the 2nd layout, at which point everything is fine and there is no more error message. Took me all day to figure this out - c'est la vie...