Hi All
Trying to delete child records on a desktop form.
The parent form, which is dimmed as frm_int, has 5 possible child tables that may contain records that need to be delete along with the parent.
The below code will work correctly for the first child (Regadless of what table i use) and will delete the header, but will will not delete any of the other child records.
Any ideas on what I am doing wrong?
Trying to delete child records on a desktop form.
The parent form, which is dimmed as frm_int, has 5 possible child tables that may contain records that need to be delete along with the parent.
The below code will work correctly for the first child (Regadless of what table i use) and will delete the header, but will will not delete any of the other child records.
Code:
mode = parentform.mode_get() if mode = "ENTER" .or. mode = "CHANGE" then msgbox("Oops", "Must save or cancel pending edits first") end end if dim frm_int as P frm_int = table.open("table_interaction") dim frm_serv as P frm_serv = table.open("table_service_request") dim frm_serv_up as P frm_serv_up = table.open("table_service_request_followup") dim frm_img as P frm_img = table.open("table_image") dim hdr_ptr as P hdr_ptr = table.open("table_shipping") dim parts_ptr as P parts_ptr = table.open("table_shipping_parts") vn_curr_ord = parentform:int_id.value ' get the curr stock order 'msgbox("int id", ltrim(str(vn_curr_ord))) parts_recs_count = a5_get_records_in_query("table_shipping_parts","int_id = " +vn_curr_ord) 'msgbox("parts recs count",ltrim(str(parts_recs_count))) if parts_recs_count > 0 then ' parts are available to be del from this order query.filter = "int_id = vn_curr_ord" query.options = "T" idx = parts_ptr.query_create() 'msgbox("part recs count", ltrim(str(idx.records_get))) else 'no parts records to delete goto del_hdr end if ' delete parts on this order parts_ptr.fetch_first() 'debug(1) while .not. parts_ptr.fetch_eof() parts_ptr.change_begin() 'delete the current parts record parts_ptr.delete() parts_ptr.change_end(.t.) 'after the del A5 advances to next record automatically xbasic_wait_for_idle() ' this line may possibly be deleted end while parts_recs_count = a5_get_records_in_query("table_image","int_id = " +vn_curr_ord) 'msgbox("parts recs count",ltrim(str(parts_recs_count))) if parts_recs_count > 0 then ' parts are available to be del from this order query.filter = "int_id = vn_curr_ord" query.options = "T" idx = frm_img.query_create() 'msgbox("part recs count", ltrim(str(idx.records_get))) else 'no parts records to delete goto del_hdr end if ' delete parts on this order frm_img.fetch_first() 'debug(1) while .not. frm_img.fetch_eof() frm_img.change_begin() 'delete the current parts record frm_img.delete() frm_img.change_end(.t.) 'after the del A5 advances to next record automatically xbasic_wait_for_idle() ' this line may possibly be deleted end while parts_recs_count = a5_get_records_in_query("table_shipping","int_id = " +vn_curr_ord) 'msgbox("parts recs count",ltrim(str(parts_recs_count))) if parts_recs_count > 0 then ' parts are available to be del from this order query.filter = "int_id = vn_curr_ord" query.options = "T" idx = hdr_ptr.query_create() 'msgbox("part recs count", ltrim(str(idx.records_get))) else 'no parts records to delete goto del_hdr end if ' delete parts on this order hdr_ptr.fetch_first() 'debug(1) while .not. hdr_ptr.fetch_eof() hdr_ptr.change_begin() 'delete the current parts record hdr_ptr.delete() hdr_ptr.change_end(.t.) 'after the del A5 advances to next record automatically xbasic_wait_for_idle() ' this line may possibly be deleted end while parts_recs_count = a5_get_records_in_query("table_service_request","int_id = " +vn_curr_ord) 'msgbox("parts recs count",ltrim(str(parts_recs_count))) if parts_recs_count > 0 then ' parts are available to be del from this order query.filter = "int_id = vn_curr_ord" query.options = "T" idx = frm_serv.query_create() 'msgbox("part recs count", ltrim(str(idx.records_get))) else 'no parts records to delete goto del_hdr end if ' delete parts on this order frm_serv.fetch_first() 'debug(1) while .not. frm_serv.fetch_eof() frm_serv.change_begin() 'delete the current parts record frm_serv.delete() frm_serv.change_end(.t.) 'after the del A5 advances to next record automatically xbasic_wait_for_idle() ' this line may possibly be deleted end while parts_recs_count = a5_get_records_in_query("table_service_request_followup","int_id = " +vn_curr_ord) 'msgbox("parts recs count",ltrim(str(parts_recs_count))) if parts_recs_count > 0 then ' parts are available to be del from this order query.filter = "int_id = vn_curr_ord" query.options = "T" idx = frm_serv_up.query_create() 'msgbox("part recs count", ltrim(str(idx.records_get))) else 'no parts records to delete goto del_hdr end if ' delete parts on this order frm_serv_up.fetch_first() 'debug(1) while .not. frm_serv_up.fetch_eof() frm_serv_up.change_begin() 'delete the current parts record frm_serv_up.delete() frm_serv_up.change_end(.t.) 'after the del A5 advances to next record automatically xbasic_wait_for_idle() ' this line may possibly be deleted end while ' del_hdr: ' now delete the frm for this order query.filter = "int_id = vn_curr_ord" query.options = "T" idx = frm_int.query_create() frm_int.change_begin() frm_int.delete() frm_int.change_end(.t.) ' now cleanup on the way out parts_ptr.close() 'close all the open tables hdr_ptr.close() frm_int.close() frm_serv.close() frm_serv_up.close() frm_img.close() 'Close the current window. 'check that you are in a window if is_object(topparent.this) then topparent.close(.f.) end if end
Comment