post images

Creating Relationships in Access

posted by trikkky on October 12, 2009

This is a follow on from creating forms in Access. First we are going to create another table and a form for our Invoices.

Create the table: Invoice

Invoice Table in Access

Save Table as Invoice TBL

Create a form from the Table Invoice

To create forms please look at creating forms in Access

Create a new form and link it to the table Invoice. Only add the Invoice number and Quantity fields to the form because we are going to create drop down boxes for the other fields.

Form Invoice

I have created my form. While still in Design view Drag a combo box on to the form, as we are going to have the Customer details.

Create combo box

Keep all settings as shown.

Select the correct Table

The Customer Table is going to provide all the details.

Select desired field

Only select the surname for your combo box. Click next on the next couple of screens and then the drop down box has all the surnames in it.

Store the Value

Select the customer number as the field value.

Name the field label

Your form should look like this

Form in Design View

Repeat the steps for Product Name

Select the wizard

For the next field we want to get our information from the Products Table.

Products

Select the Product Name and put in the opposite box

Keep pressing next until you want to store the values in the field box Product Number.

Product number Field

For the last bit Name your box Product. Add a bit of formatting to the design so your two new boxes look the same as the others.

Invoice Form

This is what I have ended up with for my Invoice form. Added a couple of buttons so when I input my data it is easy.

Creating the Relationships

Relationships

On the tool bar at the top select database tools and click on the relationship tab, Another box appears select all three of the tables then close the window. (to select all just drag down with the left button clicked down).

Three Tables

To Create the relationship click and drag the Customer Number to the Customer number on the Invoice Table. When the box appears make sure yours looks like mine with the Enforce box ticked.

Enforce Referential Integrity

When it throws an Error make sure the form is closed and only the relationships tab is open.

Linked table

We want the Product Number from the Products Table to link to the Product Number of the Invoice Table.

Connected Tables

We now have all our data connected to our tables that we want to produce invoices for the customer. The one to many relationship means that in the customer table you can only have one record with the same content, whereas in the invoice table you can many occurences of the same data. Example a customer can be on more than one invoice but only have one customer number.

Next time Querys

Written by trikkky

Has been writing posts for around ten months and has varied interests, while trying to gain a degree in web technologies.

Leave a Reply