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. To display the section name, the section number is located in the table of section numbers that is opened in the query sections1. Note the tests for the end-of-set and beginAppend( )

function messages1_section_beforeGetValue( )

   if this.parent.parent.endOfSet 

      // When navigating to end-of-set 

      return null 

   elseif this.value == null 

      // For beginAppend( ) 

      return "" 

   else 

      // Normal lookup, with value in case lookup fails 

      local r 

      r = this.parent.parent.parent.parent.sections1.rowset 

      return iif( r.applyLocate( '"Section #" = ' + this.value ),; 

      r.fields[ "Name" ].value, "Closed section" ) 

   endif 

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 number lookup is passed to applyLocate( ). dBASE Plus automatically converts the numeric field value to a string when concatenating. If a match is found, the value of the corresponding Name field is returned; otherwise, a generic string is returned.