I have a set. One parent, one child table no referential integrity. I need to run a query on the child table and remove any records from the child table that match the query. The child table is usually in change mode before I run this operation so, I check the mode of the child table and if it's CHANGE I do a tbl.change_end(.f.) then run the query. The problem I'm having is that when I put the child table into VIEW mode and run the query, it also appears to put the parent table into VIEW mode. Is there any way to prevent the parent table from going into VIEW mode when I do this?
Here is the function I call to remove the records from the child table:
Here's the script that calls the above function. It's attached to a dropdown box on my form:
Here is the function I call to remove the records from the child table:
Code:
[COLOR=darkorange]FUNCTION RemoveRecordsPieceDesc AS N (tblnum as N, vFilter as C)[/COLOR] option strict DIM tbl as P DIM qry as P DIM numrecs as N DIM commit_flag as L DIM mode as N DIM name as C [COLOR="Red"]' get a pointer to the child table[/COLOR] tbl = table.current(tblnum) 'name = tbl.name_get()[COLOR="red"] ' debug code[/COLOR] [COLOR="red"]' get the mode of the child table; usually CHANGE[/COLOR] mode = tbl.mode_get() [COLOR="red"] ' Put the child table into view mode[/COLOR] IF (mode == 1) tbl.change_end(.f.) ELSE IF (mode == 2) tbl.enter_end(.f.) END IF [COLOR="red"]' If records in tablename match vFilter, delete them.[/COLOR] qry = tbl.Query_Create("",vFilter) numrecs = qry.records_get() WHILE (numrecs > 0) commit_flag = .T. tbl.change_begin() ON ERROR GOTO error_handler tbl.delete() tbl.change_end(commit_flag) numrecs = numrecs - 1 END WHILE [COLOR="red"] ' Return the number of records that still match the query. ' 0 indicates success![/COLOR] RemoveRecordsPieceDesc = qry.records_get() qry.drop() end ' error_handler: commit_flag = .F. ui_msg_box("Error","Record number: "+ tbl.recno() + " was not deleted!") RESUME NEXT [COLOR=darkorange]END FUNCTION[/COLOR]
Code:
[COLOR=red]' Get a pointer to the parent table[/COLOR] current_tbl = table.current() [COLOR=red]' Set vFilter = OConfirmID. (My linking field for the set)[/COLOR] [COLOR=red]' To be used with a5_get_records_in_query() and Record_Delete().[/COLOR] vFilter = "OConfirmID = "+ S_QUOTE(current_tbl.ordernumb) [COLOR=red]' IF there are any records in the child table "piecedesc" that [/COLOR] [COLOR=red]' belong to the current parent table's record, prompt the user.[/COLOR] IF (dbcount("piecedesc","Oconfirmid",Oconfirm->ordernumb) > 0) response = ui_msg_box("Warning!","The piece descriptions for this order will be lost! Are you sure you want to change this field?", UI_QUESTION_SYMBOL+UI_YES_NO) [COLOR=red]' IF user clicks NO abort script.[/COLOR] IF (response = UI_NO_SELECTED) cancel() end ELSE [COLOR=red]' ELSE clear the value of the following dropdown boxes.[/COLOR] OConfirm_Form:combobox_piecedesc_stock.value = "" OConfirm_Form:combobox_piecedesc_size.value = "" OConfirm_Form:combobox_piecedesc_stockcolor.value = "" [COLOR=red]' CALL the function described in the first code snippet[/COLOR] result = [COLOR=darkorange]RemoveRecordsPieceDesc([COLOR="Black"]2, vFilter[/COLOR])[/COLOR] END IF END IF ******************************************************* ************** [COLOR=red]HERE'S WHERE MY CODE FA[/COLOR][COLOR=red]ILS [/COLOR]***************** ******************************************************* * The[COLOR=black][U][B]FIRST[/B][/U][/COLOR] time I try to set the .value of any of the fields on my form (which are bound to the parent table) [COLOR=blue](see the lines of code that fail are marked in [COLOR=red]red[/COLOR] below)[/COLOR] I get an error saying, "An Error Occured: Change must begin first" If I skip that line in the debug and continue executing the script, it's as if the table magically goes into CHANGE mode. The rest of the lines that set the .value property of the other fields on the form work fine. ??? Does anyone know why this is? ******************************************************* [COLOR=red]' Usually shows the parent table is in VIEW mode.[/COLOR] mode = current_tbl.mode_get() [COLOR=red]' IF the parent table is in VIEW mode put it into CHANGE mode.[/COLOR] IF (current_tbl.mode_get() == 0) current_tbl.change_begin() ' The line in red is the line that fails... if I comment it out the next line that sets the .value property will fail. (Highlighted in blue) [COLOR=red]OConfirm_Form:COMBOBOX_OConfirm_Form_Maildrop.value = ""[/COLOR] OConfirm_Form:LBL_OConfirm_Form_Maildrop.hide() [COLOR=blue]OConfirm_Form:tif_piecedesc_envelope.value = ""[/COLOR] OConfirm_Form:lbl_piecedesc_envelope.hide()
Comment