|
Adding a Subform to a Form in Design View
From NeoWiki
This article is part of the To Base and Back Again tutorial series.
Because the new Bird_Pictures table and form we created (See Creating a Table and a Form to Store Images ) includes a PicFieldTripID field, it would be helpful if there were an easy way for users entering data in the Bird Pictures Data Entry form to look up the Field Trip ID for a particular date without having to leave the form. We can do this by adding a subform to our form.
Create the Subform
- Open the Bird Pictures Data Entry form for editing by control-clicking on the form in the main database document window. (make sure you have chosen Forms in the left hand column of the window)
- Make sure that the Form Design toolbar is visible. (Go to the Tools menu and choose Toobars if Form Design is not checked, select it.)
- Click on the Form Navigator button on the Form Design toolbar. (It looks like a form icon with a small Navigator icon on it.) The Form Navigator
- Right-click or control-click on the MainForm icon and choose New and then Form from the contextual menu. A new form icon named Standard appears in the Form Navigator
- Right-click or control-click on the Standard form icon and choose Properties. The Form Properties window opens.
- In the Data tab, choose Field_Trips from the Content dropdown menu.
- Click on the ... button next to Link master fields. The Link Fields window opens.
- Under Field_Trips choose Date from the dropdown.
- Under Bird_Pictures choose DateTaken from the dropdown.
- Set Allow additions, Allow deletions, and Allow Deletions to no. (Obviously, if you were creating a subform for data entry, you would leave these set to yes.)
- In the General tab, give the form a more identifiable name. I chose FieldTripDates.
- Close the Form Properties
- In the Form Navigator window, make sure the subform (named FieldTripDates in our example) is selected
- Click on the More Controls button on the Form Controls Toolbar.
- In the More Controls window, click on the Table Control
- Click and drag on the form to draw the table. The Table Element Wizard - Field Selection window opens.
- In the Existing fields section of the Table Element Wizard window, select the following fields and then click the -> button after each selection to move them over to the Selected fields section.
- ID
- Date
- Location
- we are including the location field for those instances where more than one field trip occurred on the same date.
- Click on the Finish button.
- Adjust the column widths and properties as desired.
- To adjust properties, control-click on a column header and choose Column from the contextual menu.
- Save the form by pressing Command-S.
Test the form
- Shift to data entry mode by clicking on the Design Mode On/Off button on either the Form Controls or Form Design toolbars.
- Add a new entry using the following data:
- Once the data is entered, click on the subform table; you may need to wait for, but when the data is posted, a field trip should show up in the subform. You can now enter the Field Trip ID in the main form.