Home » Developer & Programmer » Forms » delete_record
delete_record [message #151068] Tue, 13 December 2005 00:07 Go to next message
VSPB
Messages: 27
Registered: August 2005
Junior Member
Hi,

I have written this code to delete any record in the block: -

DECLARE
alert_id ALERT;
num Number;
BEGIN
alert_id := FIND_ALERT('delete');
Set_Alert_Property(alert_id,title,'Confirmation');
Set_Alert_Property(alert_id, alert_message_text, 'Do you want to delete this record?' );
num := SHOW_ALERT( alert_id );
if num = ALERT_BUTTON1 then
delete_record;
commit_form;
end if;
clear_message;
if error_type='FRM' and error_code=40510 then
alert_id := FIND_ALERT('del_alert');
Set_Alert_Property(alert_id, alert_message_text, 'Cannot delete compartment, it is referred by another record.' );
num := SHOW_ALERT( alert_id );
raise form_trigger_failure;
end if;
clear_message;
End;

It deletes the record if it is not referred by any other record. But if it is referred by any other record, it gives the above message and deletes the record from the screen but not from the table, because when i exit and again open the form the record is there.

How can i stop the record from disappearing from the screen if it cannot be deleted.

Please help...

Thanks
Re: delete_record [message #151075 is a reply to message #151068] Tue, 13 December 2005 00:41 Go to previous messageGo to next message
aurigian
Messages: 9
Registered: September 2005
Location: pakistan
Junior Member

there is 2 way to do this
you apply the check "enforce data integrity" during your form creation. this check create the trigger key_delrec on block level
secondly you manualy check the record in parent table before passing delete satement and if you find the record riase the exception
Re: delete_record [message #151078 is a reply to message #151075] Tue, 13 December 2005 00:50 Go to previous messageGo to next message
VSPB
Messages: 27
Registered: August 2005
Junior Member
It is checking for the child record. It also gives proper message. It shows the alert that child record exists and when i click ok button of the alert that particular record just disappears from the screen but it is not deleted. that is fine it should not be deleted if it is referred somewhere, but it should not go from the screen if it is not deleted from the table. It should remain there only.
Re: delete_record [message #151311 is a reply to message #151078] Wed, 14 December 2005 03:48 Go to previous messageGo to next message
aurigian
Messages: 9
Registered: September 2005
Location: pakistan
Junior Member

ok fine now i get it there is only one problem
when your first alert show with this message 'Do you want to delete this record?'
and you press ok and alert return 1 and after that delete_record command execute and your form session record you need to check parents record exist or not before issue delete_record command or you add trigger "key_delrec" on block level and check parents record exist or not
Re: delete_record [message #151766 is a reply to message #151311] Mon, 19 December 2005 02:16 Go to previous messageGo to next message
VSPB
Messages: 27
Registered: August 2005
Junior Member
Yes that is what i want to do. But that is not my problem. My problem is after i click on delete it gives the message 'do you want to delete the record' when i click yes and if a child record exists for that record then it gives the message 'Cannot delete compartment. It is referred by another record.' and does not delete the record from the table. Till here it is working absolutely fine. But when it shows the alert 'Cannot delete compartment. It is referred by another record.' and i click on ok as in the picture below

C:\Documents and Settings\vsalpekar\Desktop\del_pic.bmp

it removes the record from screen like this

C:\Documents and Settings\vsalpekar\My Documents\My Pictures\doc2.bmp

as you can see the first record disappeared from the screen but it is not deleted.

I want to know how can i avoid this from disappearing.

Please help...

thanks

[Updated on: Mon, 19 December 2005 02:19]

Report message to a moderator

Re: delete_record [message #151918 is a reply to message #151766] Mon, 19 December 2005 17:53 Go to previous message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
I suggest you look to see if there are any child records before you issue your alert, tell the user whether there are child records and ask if they want them deleted as well. Then handle their reply.

But, if there are child records and the user wants to delete the parent then YOU have to decide now before you write the code as to whther it is within the business policy or not and then write code to handle it appropriately. That is, either tell the user 'NO' or delete the children and THEN issue the delete_record.

David
Previous Topic: same alert box message display twice
Next Topic: How to increment a column in Developer 6i forms automatically?
Goto Forum:
  


Current Time: Fri Sep 20 03:41:38 CDT 2024