Microsoft Access how to get a field name to only show with certain entries

1

My database in Access is listed by classification (e.g. cinema, press (local), publication (local) etc).

For the cinema classification I want to have a column titled 'the number of screens in the cinema'. However, I do not need this column for the other classifications.

How do a create a column that only appears for cinemas? I don't want the column just to be filled with N/As for non cinema classifications.

enter image description here

wilga

Posted 2018-02-26T12:24:01.587

Reputation: 79

Answers

3

What you're asking about is called database normalization. This is a design process database designers use to eliminate redundant or inconsistent data from a DB. In your case, having a Number of Screens field for records that don't have screens would not make sense, hence the need for normalization.

To solve your problem you need to add a second table to your database and put the field there. Then you link the main and second table with a unique ID field. Finally you only create a record in the second table if a record in the main table needs the additional detail.

Here's an overview of that process:

  1. Add a field to your main table of the type Autonumber. Name it CinemaID. Let Access use this as the table's Primary Key.
  2. Create another table. Perhaps name it Cinema_Detail.
  3. In the new table add a field of the type Long. Name it CinemaID (use the same name as the primary key field in the first table). Do not let Access make this a primary key. Do tell access the field is Required and values in this field need to be unique (otherwise it would be possible to have multiple records in this table that correspond to a single record in the main table, which is contrary to your request).
  4. Add another field for the number of screens.
  5. In the Database Relationship Manager, create a 1-to-Many relationship between the CinemaID fields in your two tables.

Now to specify how many screens a cinema has, add a record to the Cinema_Detail table and provide the CinemaID for the corresponding record in the main table along with the value for the number of screens.

More Information

In case you're wondering

It's not possible to do what you're asking directly in the main table. In Access fields either exist in a table, or they don't. There's no middle ground. Access is a database engine and as such it adheres to the rules of proper database design.

I say Reinstate Monica

Posted 2018-02-26T12:24:01.587

Reputation: 21 477

does this mean that all my entries will have a cinemaID even though they are not a cinema? – wilga – 2018-02-26T14:25:52.450

@wilga Yes. Based on this question do I correctly deduce that your main table has data about cinemas and some other data? If so, that needs to be fixed, or you will find it increasingly difficult to use your database. Read the article I linked for information about this. (Sorry to be the bearer of bad news--I was once in your shoes and had to learn about database design through trial-by-mistake). – I say Reinstate Monica – 2018-02-26T14:40:25.253

The main table is the media classification which amongst other entries includes cinemas. However, only with the cinemas do I want to have the additional info about the number of screens. As other media classifications don't have screens. – wilga – 2018-02-26T15:16:54.000

@wilga perhaps then all you need to do is implement my answer. As my final paragraph notes, there isn't another way to do this. – I say Reinstate Monica – 2018-02-26T15:19:16.330

So I basically just end up with 2 separate tables. 1) with everything in (apart from the number of screens. 2) with cinema screens. I've linked them in the relationship but then don't understand how these tables interact. Do I just need to open the cinema screens table to view this detail every time or is there more to this? – wilga – 2018-02-26T15:29:45.970

@wilga The usual way to interact with data in a database is through queries. You should be able to walk through the Query Wizard (in the ribbon) to create an updateable query that joins these two tables. Then you'd do your data entry via that query, not directly into the tables. – I say Reinstate Monica – 2018-02-26T15:33:43.897