help with related records

I have this code that will create a related record if there is no related record already existing. This is done when the field gains focus.

//see if the related record exists

if(!forms.contact_main.gconst01_to_address.address_id)
{
	//if not, create one and set the focus back to
	//the field they clicked in
	var fieldName = application.getMethodTriggerElementName();
	//create a new record in foundset
	forms.contact_main.gconst01_to_address.newRecord(true);

	elements[fieldName].requestFocus();
}

The problem is if statement check

if(!forms.contact_main.gconst01_to_address.address_id)

This code never works right. The condition is always skipped (never true). So I ran the debugger and watched the related field “forms.contact_main.gconst01_to_address.address_id” and it always has some number in it, even though I have no record in that related table.

What am I doing wrong? :frowning:

Do I understand correct that the relation is named ‘gconst01_to_address’? If so why don’t you do a check on child records like:```
if (!databaseManager.hasRecords(forms.contact_main.gconst01_to_address))

IT2BE:
Do I understand correct that the relation is named ‘gconst01_to_address’? If so why don’t you do a check on child records like:```
if (!databaseManager.hasRecords(forms.contact_main.gconst01_to_address))

Well, I tried that and the same problem. So I decided to create some records manually in the address table that are related to some contacts. When I viewed them from my contact form through a tab panel to the addresses, none where listed. This is maybe why it is not working.

So, do tab panels automatically show related records by the relation that is set to them?

Relation: ‘gconst01_to_address’, contact table to address table
contact_id = contact_id
globals.gconst01 = address_num

contact record:
contact_id = 7
globals.gconst01 = 1

address record:
contact_id = 7
address_num = 1

I should see this related address in my tab panel of my contact form.

Well I found out why no records would show up in the tab panel. The wrong relationship was being pumped through it.

See I have three tabs on the panel.

Tab 1 has relation 2 tied to it
Tab 2 has relation 2 tied to it
Tab 3 has relation 3 tied to it

Now another problem. How do I change the relation tied to the first tab to my reation 1 (not 2)?