Subject Conditional/filtered lookup?
Author Denis Sarrazin
I'm trying to figure out how to do a lookup that is filtered on a field in a
different table. To wit: I have a table call BUGS which contains a number of
fields, two of which are of importance here: COMPANY_ID and APPLICATION_ID. The
COMPANY_ID field points to a company table with two fields: COMPANY_ID and
COMPANY_NAME. The APPLICATION_ID field points to a table with three fields:
APPLICATION_ID, COMPANY_ID and APPLICATION_NAME.

I've managed to use the TIB_DBLookup control to show a drop-down list of
COMPANY names and another to show a list of APPLICATION names. Unfortunatly,
the list of APPLICATION names contains all of the applications, not just the
one for the currently selected COMPANY_ID in the BUGS table.

The relevant properties that I currently set are as follows (based on the
documentation in the help on using DBLookupCombos):

ibqryBug: TIB_Query
ColumnAttributes.Strings = (
'COMPANY_NAME=COMPUTED'
'APPLICATION_NAME=COMPUTED')
DatabaseName = 'dbSupport'
IB_Connection = ibconSupport
SQL.Strings = (
'SELECT BUG.BUG_ID,'
' (select COMPANY.COMPANY_NAME '
' from COMPANY '
' where COMPANY.COMPANY_ID = BUG.COMPANY_ID) as COMPANY_NAME' +
' BUG.COMPANY_ID,'
' (select APPLICATION.APPLICATION_NAME '
' from APPLICATION '
' where APPLICATION.APPLICATION_ID = BUG.APPLICATION_ID) ' +
' as APPLICATION_NAME,'
' BUG.APPLICATION_ID,'
' BUG.RECEIVED_DATE,'
' BUG.DESCRIPTION'
'FROM BUG')

ibqryApplication: TIB_Query
DatabaseName = 'dbSupport'
IB_Connection = ibconSupport
SQL.Strings = (
'SELECT COMPANY_NAME, APPLICATION_NAME, APPLICATION_ID, COMPANY_ID'
'FROM APPLICATION'
'LEFT JOIN COMPANY'
'ON APPLICATION.COMPANY_ID=COMPANY.COMPANY_ID')
KeyLinks.Strings = (
'APPLICATION.APPLICATION_ID=APPLICATION_ID')
KeyDescLinks.Strings = (
'APPLICATION.APPLICATION_NAME=APPLICATION_NAME')

ibluApplication: TIB_LookupCombo
DataSource = dataSupport.ibdsApplication
DisplayField = 'APPLICATION_NAME'

The above do show a list of applications in the drop down, but it shows all
applications rather than only the ones for the current company as selected in
the BUGS table. Is it possible for me to filter out all applications and only
show the ones for the relevant company?

Tia,
Denis