Locked lesson.
About this lesson
Add a subform to a main form and store when a record was changed in a Date/Time field.
Exercise files
Download this lesson’s related exercise files.
Services_19_Start_MainformSubform.accdb1.4 MB Services_19_MainformSubform.accdb
1.7 MB
Quick reference
Mainform and Subform
Application Terminology
Bound Control
A Bound control has a Control Source that specifies a field in the form Record Source.
Bound Form
A Bound Form has a Record Source that specified a connection to a data source such as a table or query. Bound Forms are used to enter, edit, and display data.
Calculated Control
A Calculated Control contains an expression and starts with an equal sign (=). The values in calculated controls cannot be changed by the user.
Calculations can also be added to the Record Source and the calculated fieldname can be specified in the Control Source. Again, however, the user cannot change the value.
Control
A Control is an area on a form or report that contains something.
Forms
Forms give you an easy way to enter information in the database with control to validate information, show calculations, take actions based on what is entered, and a lot more.
It is best to use Forms for entering information as opposed to entering information directly into tables. Like tables, add new records to the end of the records listed in a form.
Forms can also have subforms which are synchronized with LinkMasterFields and LinkChildFields so that values referenced by LinkMasterFields are automatically created in LinklChildFields as new records are made.
LinkChildFields
LinkChildFields are names of fields contained on a subform. The field(s) should also be in a control(s). The Visible property of the control(s) can be No, but they should be ON the subform.
LinkMasterFields
LinkMasterFields and LinkChildFields are properties of a subform control. They specify how Access links records in a main form to records in a subform.
LinkMasterFields actually refers to a control name, not a field name. This enables you to synchronize a subform with unbound controls on a main form.
More than one control can be specified. The number of items in LinkMasterFields must match the number of items in LinkChildFields. Separate multiple values with ; (semi-colon).
Access will automatically set LinkMasterFields and LinkChildFields if there is a relationship between the tables that the forms are based on and the fields are in each respective Record Source.
LinkMasterFields and LinkChildFields are listed on the Data tab of the Property Sheet when the subform control is selected.
Record Source
The Record Source of a form specifies a Table, Query, or SQL statement
Source Object
Source Object is the property of a subform control that specifies the form name to be used for the source of the subform. Source Object is listed on the Data tab of the Property Sheet when the subform control is selected.
Tab Stop
Tab Stop is a property of a bound control that determines if this control will be a place where the user will stop when they press tab
Unbound Control
An Unbound control does not contains a field name or expression in the Control Source. One use of an unbound controls is to give the user a way to specify something to search for.
Unbound Form
An Unbound Form does not have a Record Source specified and is not connected to a data source. Unbound Forms can be used for menus and dashboards.
Visible
Visible is a property of controls and sections that is Yes or No and determines if the object will be seen when a form or report is not in Design View.
Steps
Add a Subform by Dragging
- To add a subform to a main form, go into design view of the main form
- Drag a form to be used as a subform from the Navigation Pane.
- If there is not a relationship, set the LinkMasterFields and LinkChildFields properties if you wish to synchronize the main form and subform.
- Set the Name property to be the same as the Source Object property.
If you are using the same subform multiple times, add something to the end of the name to make it different.
Add a Subform by Creating a Subform Control
- Drop the list of Controls in the Controls group of the DESIGN RIBBON
- Choose the Subform/Subreport Control
- Set the Source Object property.
- If there is not a relationship, set the LinkMasterFields and LinkChildFields properties if you wish to synchronize the main form and subform.
- Set the Name property to be the same as the Source Object property.
If you are using the same subform multiple times, add something to the end of the name to make it different.
Change the Size of a Subform
- Click ONE time on the subform control
- To best-fit, double-click one of the resizing handles
- If the subform is a continuous form or a datasheet, you may want to drag the bottom or top handle to change the Height.
You can also set the size on the Property Sheet (HEIGHT, WIDTH)
Store When a Record was Changed in a Date/Time Field
- Click where the rulers intersect to select the form.
- On the Event tab, click in the form Before Update event
- Choose [Event Procedure] from the dropdown list.
- Click on the Builder button (...) to the right
or press to go to VBA - Press the (TAB) key to indent your line and type:
Me.dtmEdit = Now()
WHERE
dtmEdit is the name of your tracking field to store when the record was edited. - Choose Debug, Compile from the menu.
- Save
Lesson notes are only available for subscribers.