Alpha Video Training
Results 1 to 5 of 5

Thread: Delete Error

  1. #1
    Member
    Real Name
    Melvin
    Join Date
    Nov 2011
    Posts
    133

    Default Delete Error

    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.

    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
    Any ideas on what I am doing wrong?
    Last edited by ADCO Service; 04-10-2013 at 08:39 PM.

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Delete Error

    See this thread for some pointers.

    http://msgboard.alphasoftware.com/al...hlight=.delete


    When working on a form with a single parent visible (naturally) any code which processes child, grandchild, etc records using table current(#) affects only records related to the current parent.
    There can be only one.

  3. #3
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,699

    Default Re: Delete Error

    Hi Stan,
    It looks like Melvin is wanting to delete records in tables not currently associated in a set based form, which is what the other thread is about. If that is not the case then why open all those other tables to do queries in order to find the records?
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Delete Error

    Robin,

    You may be correct but the explanation of the intent at the start of the thread says otherwise (to me).
    There can be only one.

  5. #5
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,699

    Default Re: Delete Error

    Stan,
    It did to me too until I looked at his script. I have tables for example that belong to a Customer but do not have keys to link them directly - like invoice items on an invoice that are linked to the Inv_no not the Cust_id. Which is only an example for illustration. But there might be a similar case for how to get rid of indirectly related records. We'll have to see I guess if that is his scenario or not.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

Similar Threads

  1. Delete Record Button - Error Message
    By bavism in forum Application Server Version 11 - Web/Browser Applications
    Replies: 27
    Last Post: 05-23-2013, 02:05 PM
  2. Array Delete Error For Numeric Arrays
    By RonGiven in forum Alpha Five Version 11 - Desktop Applications
    Replies: 11
    Last Post: 04-09-2013, 07:54 PM
  3. Grid does not show error on delete when an error occurred
    By aburningflame in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 07-07-2011, 11:34 AM
  4. Script Error not allowing Add, Modify or Delete
    By Titanoguy in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 01-18-2011, 01:58 PM
  5. Error when trying to delete form
    By Flynn in forum Alpha Five Version 8
    Replies: 1
    Last Post: 03-30-2008, 07:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •