After a couple hours of playing around I came up with this function. I am using it on the CanWriteTo field event so that when the value of that field is changed that value will be passed down to the child table.
Works for any table and any field in that table. Can only write to one field and table at a time....so far...
I find this very useful, hope you do too!
Works for any table and any field in that table. Can only write to one field and table at a time....so far...
I find this very useful, hope you do too!
Code:
FUNCTION Pass_Value_To_Child AS C (vTBL AS C, vFieldName AS C, vValue AS A, vIDFieldName AS C, vIDValue AS A ) DIM vFieldType as c DIM vFieldNum as n DIM vFieldList as c DIM vField as p DIM vIDFieldType as c DIM vIDFieldNum as n DIM vIDFieldList as c DIM vIDField as p DIM tbl as p DIM myFilter as c DIM myOrder as c DIM vRecCount as n DIM pField as p DIM qry as p tbl = table.open(vTBL) 'Get the field type for the child table key field vIDFieldList = tbl.field_name_get() vIDFieldNum = word_number_get(vIDFieldList,vIDFieldName,crlf(),.t.) vIDField = tbl.field_get(vIDFieldNum) vIDFieldType = vIDField.type_get() if vIDFieldNum > 0 then myFilter = alltrim(vIDFieldName) + "=" + convert_type(vIDValue,vIDFieldType) else ui_msg_box("Error!","The ID field was not found in the child table. The ID Field Name is: " + alltrim(vIDFieldName)) end if 'Get field type for the value to be entered vFieldList = tbl.field_name_get() vFieldNum = word_number_get(vFieldList,vFieldName,crlf(),.t.) vField = tbl.field_get(vFieldNum) vFieldType = vField.type_get() 'Set the variable type of the value to be changed to the same type as the field it will be entered into pField = vField if vFieldNum > 0 then qry = tbl.query_create("",myFilter,"") vRecCount = qry.records_get() if vRecCount > 0 then tbl.fetch_first() while .not. tbl.fetch_eof() tbl.change_begin() vField.value_put(vValue) tbl.change_end(.t.) tbl.fetch_next() end while end if else ui_msg_box("Error!","The field being replaced in the child table was not found. The Field Name is: " + alltrim(vFieldName)) end end if tbl.close() END FUNCTION