In this example, a table of messages stores a message section number, but in the form, the section name is displayed in a ComboBox component. When a section is chosen by name, the section number is stored in the table instead with the following canChange event handler. The table of section numbers is opened in the query sections1.

function messages1_section_canChange( newValue )

   local r 

   r = this.parent.parent.parent.parent.sections1.rowset // Lookup table 

   if r.applyLocate( ["Name" = '] + newValue +['] ) // If name found 

      this.value = r.fields[ "Section #" ].value // save section # 

   endif 

return false // Always return false so that newValue is not saved 

In the event handler, this refers to the field. this.parent.parent refers to the rowset that contains the field (the first parent is the fields array). The form that contains the query that contains the rowset is this.parent.parent.parent.parent, from which you can reference the other queries on the form.

An SQL expression to perform the section name lookup is passed to applyLocate( ). If a match is found, the value of the corresponding section number field is stord in the value property of the field. Then the event handler returns false. If no match is found, the field is not changed.