views:

122

answers:

4

Hello,

I'm creating a database with Access. This is just a test database, similar to my requirements, so I can get my skills up before creating one for work. I've created a database for a fictional school as this is a good playground and rich data (many students have many subjects have many teachers, etc).

Question 1 What is the difference, if any, between using a Lookup column and a many-to-many associate table? Example: I have Tables 'Teacher' and 'Subject'. Many teachers have many subjects. I can, and have, created a table 'Teacher_Subject' and run queries with this. I have then created a lookup column in teachers table with data from subjects. The lookup column seems to take the place of the teacher_subject table. (though the data on relationships is obviously duplicated between lookup table and teacher_subject and may vary). Which one is the 'better' option? Is there a snag with using lookup tables? (I realize that this is a very 'general' question. Links to other resources and answers saying 'that depends...' are appreciated)

Question 2 What attracts me to lookup tables is the following: When creating a form for entering subjects for teachers, with lookup I can simply create checkboxes and click a subject for a teacher 'on' or 'off'. Each click on/off creates/removes a record in the lookup column (which replaces teacher_subject). If I use a form from a query from teacher subject with teacher as main form and subject as subform I run into this problem: In the subform I can either select each subject that teacher has in a bombo box, i.e. click, scroll down, select, go to next row, click, scroll down, etc. (takes too long) OR I can create a list box listing all available subjects in each row but allowing me to select only one. (takes up too much space). Is it possible to have a click on/off list box for teacher_subject, creating/removing a record there with each click?

Note - I know zero SQL or VB. If the correct answer is "you need to know SQL for this" then that's cool. I just need to know.

Thanks!

+2  A: 

Lookup columns in tables will cause you more stress than joy. Unless you need them for Sharepoint, they should be avoided. You may wish to read http://r937.com/relational.html and http://www.mvps.org/access/tencommandments.htm

Remou
Yeah I see that. Hmm. Thanks.OK so I will stick with the associate tables. Any idea of solving that usability problem for tick-boxing?Thanks!
TBinLondon
As mentioned by @David-W-Fenton, subforms are very useful indeed, and can be used with almost no coding and what little coding that may be required by comboboxes will be generated for you by wizards.
Remou
+1  A: 

I wouldn't use them. Your example is fine, but there are limitations. What do you do when you need to reference another field from the Subject table other than the name? How would you differentiate subjects that are only offered on a semester basis?

You have no way of getting a count of how many subjects each teacher is assigned without some ugly coding.

Another limitation, is when you start identifying who taught what courses during a given school year.

Jeff O
Okay, okay. I get it. Lookup tables are evil. I'm all in favour of adhering to received wisdom, especially in database matters.What about the second problem? I'm still toying around with it, but there seems to be no way of getting it done without some coding somewhere...
TBinLondon
+1  A: 

I'm kind of unclear on your second question, but it sounds to me like you need a subform with a dropdown list.

If you want to do the checkbox thing, it quickly becomes a lot more complicated. To me, you're starting from user interface and working backwards to structure, instead of going the other direction.

I hesitate to mention it, but in terms of full disclosure you should know that in A2007 and A2010, you have multi-value fields available, and they are presented with exactly the UI you describe. But they have many of the same problems as lookup fields, and are quite complex to work with in code. Behind the scenes, they are implemented with a standard many-to-many join table, but it's all hidden from you.

I wish MS would make the listbox with checkbox control that is used with MV fields available for all listboxes, but binding that to a many-to-many join table would be complex if the listbox control were not designed for that (with link child/link master properties, for instance).

David-W-Fenton
@ TBinLondon David mentioned multi-value fields. I'm wondering if you're already using them. If this is gibberish to you, open your table in design mode, select your lookup field, then look at the "Allow Multiple Values" property on the Lookup tab. Does it say Yes or No next to that property?
HansUp
David - yes, I'm starting with interface. Looks like I'll have to learn structure. <br> I have never heard of multi-value fields. I will look into this. Thank you. Though as it does sound like they're the same as lookup fields, and with the same issues. In the final result, I might steer clear of them. <br> your last paragraph seems to suggest that what I'm looking for does not exist in Access. Oh well. Thanks though!
TBinLondon
Hans - I had a look. Yes, I'm already using those. So, if I understand you two right, multi-value field = lookup field + "allow multiple values". It looks increasingly to me that the answer to my second question is "go learn SQL"
TBinLondon
A: 

I tried to come up with a way to offer you the UI feature you prefer from multi-value fields without actually using multi-value fields. That seems challenging to me.

The closest I could come up with is to load a disconnected recordset with your "List" choices and a check box field. Then create a form, or subform, based on that recordset which you present in datasheet view. It could look similar to a combo bound to a multi-value field. In the after update event of the checkbox field, you would need code to add or remove a record from the junction table as required.

However, I don't know if this is something you would care to tackle. Earlier you indicated a willingness to learn SQL if needed; the approach I'm suggesting would also require VBA. Maybe take a look at Danny Lesandrini's article, Create In-Memory ADO Recordsets, to see whether it is something you could use.

OTOH, maybe the most appropriate answer for you is to keep the multi-value fields and get on with the rest of your life. I'm stuck. But now that we know you are actually using multi-value fields, perhaps someone else will be able to offer you a more appropriate suggestion.

HansUp
Hans - Thanks. Disconnected recordset = table? I don't mind learning both VBA and SQL. This database is an important project. I also need to have the skills to work with it, edit, change and grow it. It'll need to be adaptable. I hoped I could do this without learning code (I like shortcuts). But so be it. As for multi-value fields, I'll not use them. I want a flexible and clean and consistent database, which multi-value fields don't provide.I'll leave this question as unanswered for a few days, in case other comments arise. The answer is what I expected and feared: learn coding.
TBinLondon
PS - I had a look at that article. Truth be told, I didn't understand 90% of it. But I'll bookmark it and return to it once I've got a better grasp at SQL/VB. Thanks.
TBinLondon
PPS - to clarify: I'm using multiple value fields AND associate tables. As this is playground for my real project, I tried both. I.e. I have a Teacher_Subject table. And my teacher table has a MV-attribute: 'subjects'; my subjects has a MV-attribute: 'teachers'. You can already see the duplicity and triplicity of data and messiness which this creates. The teacher_subject table is a lot 'cleaner'. The only issue is of course that it does not provide a checkbox function in a form. Hence my question.
TBinLondon
@TBinLondon Just as well you're not keen on the disconnected recordset; that would require more effort than I thought at first. I would do as David suggested: nail down the schema first; then decide on your forms and UI stuff. I would go with tables for Teachers and Subjects with the junction table Teacher_Subject to hold the Teacher and Subject primary keys for each Teacher/Subject combination. Sounds like you already know how to do that. That seems like the natural way to accomplish this; no multi-value fields required.
HansUp
@TBinLondon You said your project is important. If it is also non-trivial, I think you almost have to learn SQL and VBA to avoid creating a nasty mess. (Just my opinion.)
HansUp
@Hans Thanks again for the response. I didn't say I'm not keen on disconnected recordsets - I googled the term and had a look at a few articles. I kinda get it, but most of them are in programese, so I don't fully yet understand. Anyway. I agree that I'll have to learn VBA and SQL to make this work. Which is fine. I already know everything that can be done with the Access interface and some database theory (normalization, etc), so that's a start. As an aside - ideas for good beginner sources? I'm getting the 'Access 2007 Bible' from my local library and having a look at w3schools.
TBinLondon
@TBinLondon By "not keen" I meant not ready to tackle them yet, which was my impression. I shouldn't try to put my words in your mouth. :-) For beginner sources, I like John Vinson's recommendations: http://groups.google.com/group/microsoft.public.access/msg/c4be36a73171c62a Since you have some fluency with Access and fundamental database concepts you're already well ahead of ordinary Access beginners.
HansUp
@TBinLondon Earlier you asked about disconnected recordsets and tables. I wouldn't call them equivalent. Recordsets (disconnected or not) are "table-like" in that they organize data into columns and rows (or fields and records). I think a recordset is closer to the concept of a cursor in other database environments.
HansUp
@Hans - lol cool thanks. BTW Here's the definition which Access glossary help gives for recordsets. It's wonderfully (and unhelpfully) circular: "recordset: The collective name given to table-, dynaset-, and snapshot-type Recordset objects, which are sets of records that behave as objects."
TBinLondon