The problem is almost certainly this line:
@SetDocField($Ref; “Form”;(@Select((@Right(@DocChildren;”1″));AprForm) ))| @AllDescendants;
The @Right function returns a string; the @Select function is expecting a number for the first parameter.
I don’t know all the specifics about your situation, but I wouldn’t recommend going about it this way. Use a field on the parent document that evaluates to true/false; set it when you save the child document. Something like @SetDocField( $REF; “MyField”; “Yes” )