Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to multi-valued fields in MS Access

Related question: Multivalued Fields a Good Idea?

I know that multi-valued fields are similar to many-to-many relationship. What is the best way to replace multi-valued fields in an MS Access application? I have an application that has multi-valued fields. I am not sure how exactly to do away with those and implement exactly same logic in the form of fields that are single-valued?

What would be the implementation in terms of table-relationships when I want to move a multi-valued relationship to single-valued one.

Thank you.

like image 562
Jay Avatar asked Nov 22 '12 04:11

Jay


1 Answers

The following is probably far more detailed than you need, but it is intended for a beginner. Let us say you have a table, MainTable:

ID -> Numeric, primary key
Title -> Text
Surname -> Text
Address -> Text
Country -> Numeric

You will probably want a list of titles and countries from which to select.

In the case of Title, it would not be the worst thing to store the information in a field in a table, because you have a single column and the data is unlikely to change, and you probably will not be creating a query using the data.

Country is a different story, conventionally you would store a number and have a look-up table. It is the kind of situation where people are tempted to use a multi-value field.

However, convention is a lot easier. Add another table for country:

ID -> Numeric, primary key
Country -> Text

You might like to call the related field in the main table CountryID. You can now create a relationship in the relationship window showing how Country relates to MainTable:

relationship

You can see that Enforce Referential Integrity is selected, which means that you must have null or a country from the countries table in the CountryID field.

To view the data, you can create a query:

SELECT 
    MainTable.ID, 
    MainTable.Title, 
    MainTable.Surname, 
    MainTable.Address, 
    Country.Country
FROM Country 
INNER JOIN MainTable 
ON Country.ID = MainTable.CountryID;

query

But the main point is to have a form that allows data entry. You can create a form using the wizards, but after that, you either need to right-click CountryID and change it to a combobox or add a combobox or listbox using the wizard. Option 2 is probably the easiest. Here are most of the steps from the wizard:

combo1combo2combo3combo4combo5

You now have a dropdown list of countries on your form.

form

See also: create form to add records in multiple tables

In Access 2010, there are new ways of adding values to combos when the user enters data that does not exist in the table of possible values. In previous versions (although I am not sure about 2007), you would use the Not In List event to add items to a look-up table, in 2010, you have a choice of adding a List Items Edit form to the property sheet.

add item to lookup table1add item to lookup table2

like image 124
Fionnuala Avatar answered Sep 25 '22 13:09

Fionnuala