Why are lookup fields in tables so BAD

G

Guest

I constantly read refereneces to NOT to use the lookup feature in a table,
but I can't recall reasons WHY. Anyone care to offer any whys. Thanks

If I don't define the table field as a lookup, then how do I create the
lookup function on my form when using that field as the control source on my
form. That is my current dilemma, I have a field,named "location", simply
defined as "number" type in my table named "sessions". This field should
store the ID of the selected record from the "locations" table. When I add
the "location" field from the sessions table onto my CreateSessions form, I
can't find a away to make this a combo box which will then provide the lookup
functionality I need.

So how do I create teh lookup functionality on the form?

Thanks for explanations and suggestions
 
J

Jeff Boyce

Lookup fields in tables are not inherently evil.

Lookup fields in tables store one thing (the lookup table's row's ID) but
display something else (the looked-up value). If someone is working
directly in the table, or is working on a query and is trying to find a
value that matches what is displayed, ... CONFUSION!

The lookup TABLE is a great idea, making it easier for users to select
appropriate values. In a form, add a combo box (or a list box) and base it
on the lookup table. Hide the ID field (column width property = 0) and
display the looked-up value.

This approach lets the users pick something they know (like a person's name,
rather than the employee_ID).

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

George Hepworth

Jeff:

In THEORY, you're right that the lookup field in a table can (correctly) be
designed to store IDs while displaying the lookup value. However, it is also
possible to screw this up by storing the display value instead of a Foreign
Key, which I have seen done. If someone doesn't understand what they are
doing, they can go wrong quickly and badly. That's one of my major
objections to the use of lookup fields in tables.

George
 
G

Guest

I certainly agree that the mechanics of recording one thing and displaying
someting else can be confusing. Definitely confused me when I first started,
and still does. When I have a field defiend as number and it it displays
"classroom3" for instance. But to classify something as evil just because
others may not immediately seems an antiquated philosophy. OFF my soap box
now! Is this "confusion" issue the primary reason for NOT defining the table
field as a lookup? I find the abiolity to have my forms automatically
recognize the lookup function when the field is attached to a form to be
quite a boost to productivity. What evil landmines have I avoided without
even knowing I was in a minefield?

I admit I still appreciate the drag and drop capability of creating forms
and reports in Access. I even use the wizards occassionally to do perform the
bulk of the work and then just tweak to my specifications.

So how do I change that form field to a combo box and set up the lookup
functionality? I can't find a Row Source type or Row Source filed on the
form field created by drag and droping the location field from the table to
the form. Or do you recommend deleting my form field and creating a new field
from the toolbox, then having to rekey all the controls that that were filled
in by the drag and drop method?
 
B

Bob Quintal

So how do I change that form field to a combo box and set up the
lookup functionality? I can't find a Row Source type or Row
Source filed on the form field created by drag and droping the
location field from the table to the form. Or do you recommend
deleting my form field and creating a new field from the toolbox,
then having to rekey all the controls that that were filled in by
the drag and drop method?
After dragging and dropping, Select the textbox. Click the Format Menu
item and mouseover Change to -> select combo box. You will need to
manually set the rowsource, just type the lookup table name. and tweak
the column widths to your liking.
 
A

Albert D. Kallal

First, they are not really that bad, but when you run into trouble with
them, you will find that you begin to dislike then very much!

So, I going state that as long as they work for you, the more power
to you!

Now, lets clearly define what those developers are talking about!

Use of the lookup wizard feature at the TABLE DESIGN level

I repeat: lookup feature at the TABLE desing level is the the thing to
advoid.

In other words, you are encouraged to use the combo box wizard in a form.
You are even ok to use the lookup wizard when you build a query (often, many
people don't realize that the lookup wizard also works when you build a
query!). However, since you are in the query builder, it is probably much
nicer to draw a join line, and use the relation ability of the query builder
to pull in that lookup value you need to lookup via a join. (ie: it is much
clear and better to simply drop in the additional tables into the query
builder
instead of using lookups).
(more on this in second)..

So, as a general concept of database designs, you encouraged to pull data
from tables all the time. This idea of pulling values from other tables is
the very essence of a relational database. So, yes, use good designs that
encourage values to be looked up from other tables (but, avoid that lookup
feature at the table level). You build and design tables in a database. You
then join these tables together. However, each table should have it fields,
and when you need to lookup values in other tables, you use sql to do this.

So, lots of relations, and looking up values is encouraged in your designs.

However, at the table level, there is few problems as to why the lookup
wizard feature is bad:

The often quoted reason is that then the novice user will NOT know what is
going on! Golly, that is not the best argument here! After all, we can drive
our car to work, and we don't know what the motor does, or even what it
looks like! That don't mean we should not drive!

I mean, the look up feature is there to help users, and make things easy.

However, here is some REAL pit falls:

First, in any good application design, you will RARELY be editing the data
in the tables directly. So, most of the time, we are talking about a
continues form, or a standard data entry form. This means the benefits of
the lookup are very much reduced. (in those forms, you can quickly build the
combo box with the combo box wizard, and this is most certainly encouraged).

Anyway, just try and build a simple report based on that table with a lookup
field. The first problem that arises is that the text box on the report will
appear by default as a combo box. That don't look very good. Worse, is now
try and use the sorting and grouping options in the report. You get the
weird situation where in the sorting and grouping option, your report will
sort by the ID value, but display by the look up value! This is sheer
confusing, and it don't make sense.

You will say, golly, why does this thing not sort by the value it displays?
Worse, is how do you in fact sort by the actual looked up value? I mean if
we have a simple list of fruits in a look up table, we probably will want to
sort by the looked value! The problem is that you can NOT sort by the look
up value! The end result is you dump the table lookup feature, and then have
to build a query and join in the actual text value of the fruit from that
table into the reports query anyway!. You then can sort on that! (wow...that
built in lookup feature did not save one bit of work here...did it!).

So, your report will sort by the id value, and displays the by lookup value
unless you dump the use of the lookup. Yuk!

What if you load the data into a reocrdset, then again, what do you get for
the lookup value field? (you get the id value, and again, if you need to get
the value from the other table, you wind up creating a query again! (or
write some code to grab the text value in the lookup table). So, once again,
in code with reocrdsets, the table lookup feature does nothing, and again
tends to surprise the developer as to what value will be returned!. Once
again, you don't save any coding by using this table lookup do you? (it is
ignored in reocrdsets). If you had used a query in the first place, then
in your code, both the ID, and the description would be available
WITHOUT any extra coding!

Further, lets say later on we decide add another field to our fruits table.
Lets say we need to add the colour of the fruit. You have to realize that
over time, database do change a lot! You must *design* for change!

So, now we just add an additional field to the fruits table called colour.

Now, go back to those reports and drop in the colour field beside the fruit
text! OOPS, can't do that!! Of course, the fruit name is a lookup Value.
However, to display the fruit name AND THE colour, then all of those
queries, reports etc. will now need to be modified to display the colour of
the fruit. And of course, to bring in this additional field of colour, we
CAN NOT use the table lookup feature.

Of course, what is really is the problem here is that will have to build
queries to do this! Something we should have done in the first place!!!!
Now, you got a report with both lookups and a join to this other table.
Well, golly, you might as well dump the lookup, since you have to bring in
the (two) fields from the fruits table via sql joins anyway! If you had
built
queries in the first place, then you would just simply plop in this extra
field into the report, and you are done. With the table lookup approach, you
are now stopping in the 12 places in the database, and now building the
queries, or even changing the report source from a table to query. This work
really starts to add up, and bogs you down because of poor design choice in
the first place. We should be able to add this additional field, and not all
of sudden stop dead in our tracks to build queries everywhere.

Worse, it gets messy, as all of a sudden you have to decide if you want dump
the table lookup, as it does not make sense to have both a look up field,
and then some additional fields from that same lookup table brought in via a
sql query join! Yuk!. Worse, after you get knee deep into the project, you
CAN NOT safety remove the lookup field, as then you might introduce bugs and
will have to hunt down every single spot (form, report etc) in the database
that relied on the table lookup feature (that you are now trying to
remove!).
!
So, there is some frustrations in using the lookup. However, if you have not
run into the above problems, then it is most un-fair of me say don't use
them. There is tons of users out there that use and enjoy, and even find
increased productivity from using the table lookup feature. I have to say
that your mileage will vary on this one.

However, due to problems like the above, I do advoid them. Futher, advoiding
them makes you learn the correct skills for other sql database systems you
will use.
 
G

George Hepworth

Albert:

Although I agree with most of what you've said, I remain convinced that
avoiding lookup fields in tables is a good practice for the great majority
of people.

My argument against lookup fields is based on direct experience
trouble-shooting problems for posters at UA who have screwed themselves over
by trying to use lookup fields in tables and doing so incorrectly.

I don't think it's the same as driving a car without knowing how the engine
works. It's more like putting diesel into a gasoline engine because gas and
diesel smell a lot alike. By the time you figure out something is wrong, the
damage has been done, and fixing it is more costly and time-consuming than
getting it right the first time.

George
 
B

Bob Quintal

Thanks Bob, That little tidbit really helped. Isn't it amazing how
every time you find one answer it creates two more questions?

My combo box uses 3 columns from my participant table; ID, fname,
and lname. ID is teh bound column, however I would like to provide
the lookup based on fname. Of course the table is sorted on ID. IS
there a way I can set the order in the combo box to Fname without
changing the sort order of the table. To have all the JAmes'
display together so selecting the correct James is just a matter
if scrolling over to find the matching Lname.

Thanks
Real easy. Click in the rowsource box in the properties. A little
button with an ellipse (3 dots) will appear to the right. Click it.
It will pop up a message that says "You Have invoked the query
builder on a table. do you want to create a query based on the
table?

Click yes, bring down each of your fields, set the Sort to ascending
in the Fname, and close the query builder, answer yes to to the save
changes question. the query's SQL is now stored in the Rowsource

save the form.

Bob Quintal said:
After dragging and dropping, Select the textbox. Click the Format
Menu item and mouseover Change to -> select combo box. You will
need to manually set the rowsource, just type the lookup table
name. and tweak the column widths to your liking.
 
G

Guest

Thanks Bob, That little tidbit really helped. Isn't it amazing how every time
you find one answer it creates two more questions?

My combo box uses 3 columns from my participant table; ID, fname, and lname.
ID is teh bound column, however I would like to provide the lookup based on
fname. Of course the table is sorted on ID. IS there a way I can set the
order in the combo box to Fname without changing the sort order of the table.
To have all the JAmes' display together so selecting the correct James is
just a matter if scrolling over to find the matching Lname.

Thanks
 
G

Guest

Thanks for taking the time to specify some of those frustrations that await
me! No I have abetter understanding of these warnings.

Thanks again
 
G

Guest

Thanks again. That one I SHOULD have remembered. I think my mind must not be
back from vacation yet, hope it shows up soon.

Thanks to all.

Bob Quintal said:
Thanks Bob, That little tidbit really helped. Isn't it amazing how
every time you find one answer it creates two more questions?

My combo box uses 3 columns from my participant table; ID, fname,
and lname. ID is teh bound column, however I would like to provide
the lookup based on fname. Of course the table is sorted on ID. IS
there a way I can set the order in the combo box to Fname without
changing the sort order of the table. To have all the JAmes'
display together so selecting the correct James is just a matter
if scrolling over to find the matching Lname.

Thanks
Real easy. Click in the rowsource box in the properties. A little
button with an ellipse (3 dots) will appear to the right. Click it.
It will pop up a message that says "You Have invoked the query
builder on a table. do you want to create a query based on the
table?

Click yes, bring down each of your fields, set the Sort to ascending
in the Fname, and close the query builder, answer yes to to the save
changes question. the query's SQL is now stored in the Rowsource

save the form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top