Since you are making the subform record from the same database form that the subform is attached to, you will have to use following method.
If @clientLocalValue ("Process") = "Success" and vDescription <> ""then //only when processed properly - to avoid putting value in Document subform
{
If vDescription <> "" and @FormFieldValue ("Documents", "Description", 1) = "" then
{
//nn = @FormNewRecord ("Scripts2")
//WriteLN ("vLoop = " + @str (vLoop))
//WriteLN ("nn = " + @str (nn))
FormresultsetCurrentPosition ("Documents", 1)
FormFieldValue ("Documents", "RecNumber", 1, vRecNumber)
FormFieldValue ("Documents", "DateAdded", 1, vDateAdded)
FormFieldValue ("Documents", "Chart", 1, Chart)
FormFieldValue ("Documents", "Description", 1, vDescription)
FormFieldValue ("Documents", "View", 1, vView)
FormFieldValue ("Documents", "FileName", 1, vFileName)
FormFieldValue ("Documents", "Key", 1, vKey)
FormFieldValue ("Documents", "Print", 1, @Chr (252) )
FormCommit ("Documents")
}
Else if vDescription <> "" and @FormFieldValue ("Documents", "Description", 1) <> "" then
{
nn = @FormNewRecord ("Documents")
//WriteLn ("The value on nn = " + @Str (nn) )
//WriteLN ("vLoop = " + @str (vLoop))
//WriteLN ("nn = " + @str (nn))
FormFieldValue ("Documents", "RecNumber", nn, vRecNumber)
FormFieldValue ("Documents", "DateAdded", nn, vDateAdded)
FormFieldValue ("Documents", "Chart", nn, Chart)
FormFieldValue ("Documents", "Description", nn, vDescription)
FormFieldValue ("Documents", "View", nn, vView)
FormFieldValue ("Documents", "FileName", nn, vFileName)
FormFieldValue ("Documents", "Key", nn, vKey)
FormFieldValue ("Documents", "Print", nn, @Chr (252) )
Formcommit ("Documents")
}
First it checks whether the first record is blanked or not. Logic is the first record in the subform always exists. If it is blank you just fill it up. Subsequent record you make and fill it up.
I have gone through this frustrations in the past. But now it is clear. If you make subrecord from other database, you use XResultset command. If you make it from the same database form, you use @Formfieldvalue ( ). I am quite sure this should work for you.