Subject Selective lookup
Author s.beames@mailbox.gu.edu.au
Hi,
is it possible to restrict the records displayed in a
TIB_LookupCombo based on a relationship defined in a third table?

My 3 tables are:

Table: ACCNTS_USED (for a job, KeySource table)
PK
JOBNO
ACCNTHLDR
ACCNT_ID
~

Table: ACCOUNTS (All existing accounts, Lookup table)
ACCNT_ID (PK)
ACCOUNT
SPEEDTYPE
CLASS

Table: ACCNTHLDRS_ACCNTS (Link table)
PK
ACCNTHLDR
ACCNT_ID

I decided I needed the link table because each user can use several
accounts, and each account can be used by several users.

My lookupcombos are displayed in a grid (because costs for a job can
be shared amongst several accounts).
In operation, the user first selects an ACCNTHLDR from the first
TIB_LookupCombo, and I then want to display only the accounts linked
to that ACCNTHLDR in the next TIB_LookupCombo in the row.

Sounds easy enough, but I can't get it to work!

Lookup SQL is
SELECT ACCNT_ID
, ACCOUNT
, SPEEDTYPE
, CLASS
FROM ACCOUNTS

KeyLinks -
ACCOUNTS.ACCNT_ID=ACCNTSUSED.ACCNT_ID

So far, so good! This displays all accounts details in the lookup-
combo.
If I try to restrict the returned rows with

void __fastcall TJobsForm::AccntLUQryPrepareSQL(TIB_Statement *Sender)
{
AccntLUQry->SQLWhereItems->Add
("ACCNTSUSED.ACCNTHLDR=ACCNTHLDRS_ACCNTS.ACCNTHLDR");
}

I get an error of "Column unknown ACCNTSUSED.ACCNTHLDR".
How do I let IBO know about this other column of my Keysource table?
I can't seem to find the right SQL statement that doesn't give
me "Multiple rows for singleton select" type errors.

Thanks for any advice,
Steve