Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you ensure at least 1 detail rec for a master rec?

Status
Not open for further replies.

AppBldr

Programmer
Sep 27, 2000
14
0
0
US
I've got a master/detail relationship with the master record in one table and detail records in another, joined on a key field. I want to make sure the user can't save a master block record without having at least 1 (valid/complete) record in the detail block, but this is my first attempt at this and I'm floundering.

It saves fine to both tables if you enter the data correctly, but I don't know how to loop through the detail block to see how many records are entered or to validate more than just the first one.

On the When_button_pressed trigger of the Save button, I call a function to validate the data in both blocks. I am using Get_Block_Property (block_name, CURRENT_RECORD) to find out about the first record in the block, but I don't know what to do from there -- how to loop through, what to do if I do find an error, or how to let them save the corrected version.

Any insight would sure be appreciated... Thanks!
Carolyn
 
Hi,

My experience (other solutions could work better):

in the key_commit trigger at form level, put:

go_block('detail_block');
first_record;
if :system.last_record = 'TRUE' and :detail_nlock.relation_column is null THEN
-- no data
Message('you're a bad guy...');
raise form_trigger_failure;
END IF;
...

COMMIT_FORM; -- Do forms save the data

To put the code there make you sure that whichever mean the user use to save, it will be executed.

Hoping this helps,

Regards,

Christian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top