I have been using the code to make a document subrecord and then reparent it to the mainform. It works fine when I execute from the Layout in the different database but if it is initiated from the Layout of the same database where this subform belongs to, it does not add the subrecord in the form. The subrecord is made but it does not get reparented. When I execute the same code from different database form, the earlier subrecords also shows up along with the new subrecord created.
vChildRSID = @XResultSetSearch(@FN, "Index!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart==")
If vChildRSID > -1 then
{
xResultSetCreateNewRecord (vChildRSID)
xResultSetValue (vChildRSID, "RecNumber", vRecNumber)
xResultSetValue (vChildRSID, "DateAdded", vDateAdded)
xResultSetValue (vChildRSID, "Chart", vChart)
xResultSetValue (vChildRSID, "Description", vDescription)
xResultSetValue (vChildRSID, "View", vView)
xResultSetValue (vChildRSID, "FileName", vFileName)
xResultSetValue (vChildRSID, "Key", vKey)
xResultSetClose (vChildRSID)
}
vParentRSID = @XResultSetSearch(@FN, "Index", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + vChart)
/*
If @XResultSetLocked (vParentRSID) = 1 Then
{
@MSGBox ("Parent ResultSet is Locked", "The Document will not go to DocumentSubform", "Process it from Other Database")
}
Else If @XResultSetLocked (vParentRSID) = 0 Then
{
WriteLn ("Parent ResultSet is Not Locked")
}
*/
If vParentRSID > -1 then
{
vRecordsFound = @XResultSetTotal (vParentRSID)
If vRecordsFound = 1 then
{
vChildRSID = @XResultSetSearch(@FN, "Index!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + vChart)
If vChildRSID > -1 then
{
//WriteLN ("You were in ChildRSID")
//WriteLN ("Total subrecords are " + @Str (@xResultSetTotal (vChildRSID )) )
xResultSetSort (vChildRSID, "DateAdded:1")
xResultSetReparent (vParentRSID, "DocumentSubForm", vChildRSID)
xResultSetClose (vChildRSID)
}
}
Else if vRecordsFound = 0 then
{
WriteLN ("Chart " + vChart + " Does not exist in INDEX Database!!! Please Correct it" )
vFailureIndicator = 1
}
Else if vRecordsFound > 1 then
{
WriteLN ("Chart " + vChart + " has Multiple Entries in INDEX Database!!! Please Correct it" )
vFailureIndicator = 1
}
XResultSetClose (vParentRSID)
}
xResultSetClose (vChildRSID) // for additional precaution - in case if it is not closed
xResultSetClose (vParentRSID) // for additional precaution - in case if it is not closed
I have tested to the extent that neither Parent nor Child resultsets gets locked up, still the xResultsetReparent ( ) command fails to work when executed from the database form where this subform is located. The subrecord is made properly but does not show up in the subform.
I cannot use @FormfieldValue ( ) to fill up the subform record as the form that has the subform is usually not open and this code is initiated from the different form of the same database.
How can I make the code work when it comes to be executed from the same database form? Any suggestions?