05 access howtolookupselect
-
Upload
rebecca-jones -
Category
Education
-
view
1.405 -
download
0
Transcript of 05 access howtolookupselect
MS Access How To:Look up and select values
Unit 18 Database DesignExtended Diploma in ICT
Link tables• A link table will have foreign keys• To create a record you want to select a value from another table and put the key value in the link table• You do this using list boxes
Example• You want to select a customer, then a costume and put the key
values for those selections into the rental table
Create a form• Make a form for the link table• Add the foreign key IDs
Add a list box• Click on the List Box control and drag out a list box• The List Box Wizard starts
List box control
List box wizard• Choose the list box to look up the values in a table or query
List box wizard• Select the table you will look up
List box wizard• Choose the fields that will appear in the list
box• Pick the primary key first
List box wizard• Choose any sorting that you want
List box wizard• You are shown a preview
• You now choose to save the primary key value from the list box in the foreign key field on the form
List box wizard• Type a label for the list box
List box wizard• The wizard closes and the list box allows you
to select a customer and put the ID in the correct field
Adding a subform to show more detail• There are more customer details you may
want to show, such as the address. • You can use a subform for this• Click on the subform control and draw out a
subform
Subform control
Subform• The subform wizard opens• Choose to use an existing table or query
Subform• Select the right table and the fields you want
to show• You must include the key
Subform• Choose from the list and the subform will
show the values from the table associated with the primary key in the link table
Subform• Give the subform a sensible name
Subform• The subfom is created (and looks awful)
Subform appearance• We need to improve its appearance
Subform property sheet• Set
• Default view to Single Form• Record selectors to No• Navigation buttons to No• Scroll bars to Neither• Delete the label
Subform appearance
Subform update• The subform updates when you use the
record selectors, but not when you use the list box
• Fix this using some VBA (Visual Basic for Applications)
Subform update• Select the list box• Then click on the three dots in the After Update property
List box selected Three dots
VBA• A dialogue box opens and you choose Code
Builder
VBA
• The VBA code window opensSpace for your code
Form this event
applies to
Event this code
applies to
VBA• We want the subform to update after we have
clicked to select a customer.
Refresh the main formRequery
the sub form
End result• The data will now match the selection in the
list box