Subject Re: [IBO] TIB_LookupCombo question
Author Helen Borrie
At 11:13 AM 30/09/2006, you wrote:
>I have an application where I need to keep track of classes what
>students wish to sign up for in different quarters of the school
>year. I have a table that stores all available classes.

Suppose the table consists of
Class_ID integer primary key
Class_Description varchar(50)

The structure of your query will need to be

select Class_ID, Description from Classes

>I have a form that has several tib_lookupcombos.

>In the BDE version, since
>the lookupcombo has both a list source/keyfield and a
>datasource/datafield relationship, I can have all of the
>lookupcombos accessing the same "classes" table yet updating
>different fields in the student file so the student can sign up for
>4 different classes, 1 per school quarter. In the IBO version I
>can't figure out how to accomplish the same thing.

OK, the native IBO controls are *not* descended from VCL controls
that have similar behaviour. The IBO controls are driven entirely by
the data and the relationships between your sets. The terminology is
different because, although the effect appears similar, the technical
concepts being realised are different. Stay with me. :-)

>Since the tib_lookupcombo only has a datasource and, as far as I can figure,
>the relationship is set using keylinks,

The crucial missing piece here that you have not mentioned is
KeySource. Set the KeySource property of each lookup dataset to be
the Datasource of the main set.

The Datasource property of the ib_lookupcombo points to the
datasource of the lookup set.

>am I limited to one tib_lookupcombo on the form since adding more
>continue to update the same field in the students file based on the
>defined keylinks.

No; if you wish to use lookups for each of the four relationships
and you want it to be fixed at design time, then you must have one
tib_lc for *each* relationship AND one lookup query for each relationship.

>I realize that I can keep changing the keylinks but that only semi
>works because it messes up the display since once changed the
>tib_lookupcombo that displayed class x now displays class y because
>the keylink effects all of tib_lookupcombos on the form. Can
>someone tell me what I am missing?

It sounds to me as though you are trying to share a single TIB_Query
lookup query and datasource between the four ib_lookupcombo
controls. Don't do this if you wish to use the ib_lc as a way to
display the current data. The control is designed to realise a
single relationship. These are four different relationships so they
are four different sets. That means four ib_queries and four
ib_datasources. Each lookup dataset will point to the same KeySource
but the KeyLinks will be different for each one.

I'll use a simplified example, although I expect your main query's
structure will be more complex, involving a join to an intersection
table to make it possible for a student to enrol in more than one
class per semester.

Suppose your Keysource query is:

SELECT
s.Student_ID,
s.Semester_1_Class,
(select c1.Class_Description from Classes c1
where c1.Class_ID = s.Semester_1_Class) as s1class,
s.Semester_2_Class,
(select c2.Class_Description from Classes c2
where c2.Class_ID = s.Semester_2_Class) as s2class,
s.Semester_3_Class,
(select c3.Class_Description from Classes c3
where c3.Class_ID = s.Semester_3_Class) as s3class,
s.Semester_4_Class,
(select c4.Class_Description from Classes c4
where c4.Class_ID = s.Semester_4_Class) as s4class
from Students s

Call the query qrStudents, call its datasource dsStudents.

Our four lookup queries, call them qrSemester_1, qrSemester_2,
qrSemester_3 and qrSemester_4, will all have the same SQL:

select Class_ID, Description from Classes

All of the datasets will have the same KeySource property, dsStudents.

qrSemester_1:
KeyLinks: Class_ID=Semester_1_Class
KeyDescLinks: Description=s1class

qrSemester_2:
KeyLinks: Class_ID=Semester_2_Class
KeyDescLinks: Description=s2class

qrSemester_3:
KeyLinks: Class_ID=Semester_3_Class
KeyDescLinks: Description=s3class

qrSemester_4:
KeyLinks: Class_ID=Semester_4_Class
KeyDescLinks: Description=s4class

Set up 4 datasources, dsSemester_1, dsSemester_2...and so on.
Link each ib_lookupcombo control to the correct Datasource and you
are "in business".

I noticed others trying to help you to use only *one* ib_lookupcombo
control against all four fields in the KeySource set, setting the
KeyLinks at run-time. This is possible, too, although not quite as
they have described it. However, it doesn't seem to be what you were
asking about.

Helen