Natalie,
Bob is correct, "we are working at the wrong level of forms".
To add a new record to a subform, you need to use @FormNewRecord("MySubform") rather than @CreateNewRecord().
To check the content of a LE in a subform, you need to use @FormFieldValue("MySubform", "MySubformLE", SubformInstance).
Based on what I believe you are asking, this is the general structure you probably need to use:
var nn as int
if @FormFieldValue("MySubform", "MySubformLE", SubformInstance) <> "" //Check if subform LE is not blank
{
nn = @FormNewRecord("MySubform")
FormFieldValue("MySubform", "MySubformLE", nn, MyValue) //Post to new subform record. nn is the subform instance created above.
}
The last line demonstrates how you would post data to the subform record. It will post a value to the newly created record.
You also need to figure out which
instance of subform to check, for the blank LE. If you simply need to check the last one, you can use @FormResultSetTotal("MySubform") to find it.
------------------------------------------------------------------------
The previous info is based on what I first thought you asked for. But, it also sounds like you may want to use the following code instead. It will add a new subform record every time you click on the Ticket button, except when you don't have any subform data yet (like when the parent is new). It will check the first subform instance to see if it is blank. If it is blank, it will add the data to that first subform record. Otherwise, it will add a new subform record, and post the data to the new one.
var nn as int
if @FormFieldValue("MySubform", "MySubformLE", 1) <> ""
nn = @FormNewRecord("MySubform")
else
nn = 1
FormFieldValue("MySubform", "MySubformLE", nn, MyValue)
This is actual code that I am using in one of my apps.