Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 36 ยท Forms and Reports

Form Controls, Combo Boxes, Subforms and Buttons in Access

Add and configure Access form controls: text boxes, combo boxes, option groups, subforms with link fields, calculated controls, command buttons and conditional formatting.

Controls are the building blocks of a form. Choosing the right control makes data entry faster and more accurate: a combo box that lists valid customers instead of a text box where people mistype names, a subform that shows an order's lines on the order itself, a button that opens another form.

This lesson tours the common controls, shows how to set up a combo box and a master and detail subform, explains calculated controls and conditional formatting and introduces command buttons. Everything happens in Design view or Layout view; open the form and switch with Home > View.

Adding controls

In Design view the Form Design tab shows a Controls gallery. Click a control type, then click or drag on the form. If the Use Control Wizards button (the wand under the gallery) is on, many controls start a wizard that sets properties for you.

To add bound fields, open Add Existing Fields and drag a field onto the form. Access picks a control type from the field's type: a text box for text and numbers, a check box for Yes/No, a date picker for dates and a combo box for lookup fields.

Control Best for
Text box Typing or showing a value; also calculations
Label Fixed text and captions
Combo box Choosing one value from a list that can also be typed into
List box Showing a visible list of choices
Check box Yes/No
Option group Choosing one of a few exclusive values (radio buttons)
Toggle button A Yes/No shown as a button
Command button Run a macro or code on click
Tab control Split a busy form into pages
Subform/Subreport Embed another form that shows related records
Image A logo or picture
Line / Rectangle Visual structure
Web browser control Show a web page or HTML

Pick the right control

Text box Free typing and calculations
Combo box Choose from a list
Check box Yes or No
Option group One choice of a few

A list control prevents typing mistakes.

1 / 2

Text boxes and labels

Each field you drag creates a label attached to a text box. Select the text box and press F4 to open the Property Sheet. The important tabs are Format (appearance), Data (Control Source, Default Value, Validation Rule, Locked, Enabled), Event (macros and code) and Other (Name, Tab Stop, Tab Index, Status Bar Text).

Give controls meaningful names on the Other tab, with a prefix such as txt, cbo, chk, cmd, lst, fra or sub: txtCustomerName, cboCountry. Names matter once you refer to controls from queries and VBA.

Combo boxes

A combo box shows a drop-down list. There are two sources of choices:

  1. Value List: you type the items. Good for short, fixed lists.
  2. Table/Query: the list comes from a table. Good for anything that can change.

Use the Combo Box Wizard, or set properties on the Data tab:

Property Typical value
Control Source CustomerID (the field in the form's table)
Row Source Type Table/Query
Row Source SELECT CustomerID, CustomerName FROM Customers ORDER BY CustomerName;
Bound Column 1 (store CustomerID)
Column Count 2
Column Widths 0";2" (hide the ID, show the name)
Limit To List Yes

Users see names. The form stores the ID. This is the foreign-key pattern from the relationships lesson made friendly.

The Row Source is an ordinary query, as this example shows:

SQL The query behind a customer combo box

Press Run (or Ctrl + Enter) to see the result here.

A cascading (dependent) combo box limits one list by another selection: cboCity filters by cboCountry. The Row Source of cboCity has a criterion that refers to the first combo: WHERE Country = [Forms]![frmCustomer]![cboCountry]. Add Me.cboCity.Requery in the After Update event of cboCountry to refresh the list.

Option groups and check boxes

An option group holds several option buttons, each with an Option Value (1, 2, 3). The group stores the number of the selected one. Use it when the field holds a small fixed set of numeric codes. For text codes, use a combo box instead.

A check box binds to a Yes/No field. Set Triple State to Yes if you need a third, "unknown" state (Null).

Subforms: showing the many side

The subform control embeds a form inside a form. This is how you show a customer and the customer's orders, or an order and its line items, on one screen.

Easiest way: select the parent table (Customers), choose Create > Form and let Access add the subform automatically if a relationship exists. Or, in Design view, make sure Use Control Wizards is on, drag the Subform/Subreport control onto the main form and follow the wizard.

The two forms are connected through two properties of the subform control (on the Data tab of its Property Sheet):

  • Link Master Fields: the field in the main form, such as CustomerID.
  • Link Child Fields: the matching field in the subform's record source, such as CustomerID in Orders.

When the main record changes, the subform shows only child rows whose child field equals the master value. New child records get the master value filled in automatically.

Typical subform settings: Default View = Continuous Forms or Datasheet, Navigation Buttons = No, Record Selectors = No.

The query a subform runs is just a filtered select:

SQL What a subform shows for one customer

Press Run (or Ctrl + Enter) to see the result here.

Calculated controls

A text box with a Control Source that starts with = shows a calculation and is not editable:

Text
=[Quantity]*[UnitPrice]
=[FirstName] & " " & [LastName]
="Total: " & Format([Total],"Currency")
=Sum([Total])
=Count(*)

Sum and Count work in a form header/footer. To show a subform's total on the main form, place a text box in the subform's footer, name it (say txtSubTotal) and refer to it from the main form:

Text
=[sfrmOrders].[Form]![txtSubTotal]

A calculated control is not stored in the table. If you need to store it, bind a normal control and set its value with code or a macro, or use a calculated field in the table or query.

Command buttons

A Command Button with the wizard on offers actions grouped by category: Record Navigation (go to next record), Record Operations (add, delete, save, undo), Form Operations (open or close a form, print), Report Operations (preview or print a report), Application (quit), Miscellaneous and more. The wizard builds an embedded macro or VBA for you in the button's On Click event.

Name buttons with a cmd prefix and set a clear Caption. A button that deletes something should ask for confirmation.

Use Alt access keys in captions by putting & before a letter: the caption &Save shows Save underlined, and Alt+S runs it.

Conditional formatting

Highlight rows or values with Format > Conditional Formatting. Select a control, click Conditional Formatting on the Format tab and add a rule: for example, if Stock is less than 10, show the text in red and bold. Rules can compare the field value, test an expression or add data bars. You can set up to 50 rules per control in current Access.

Tab control and layout tools

A Tab Control splits a crowded form into pages (Details, Orders, Notes). Place controls on each tab page, and Tab Index works within each page.

On the Arrange tab, use Stacked and Tabular layouts to keep controls aligned as a group; Anchoring keeps controls pinned when the window is resized; Size/Space and Align fix pixel-level differences. Layouts make editing in Layout view much easier. To place a control freely, select it and choose Remove Layout.

Events: a first look

Every control and form has events that fire at set moments: On Click, After Update, On Current (when the record changes), Before Update, On Open and so on. You attach a macro or VBA procedure to an event on the Event tab. The macros and VBA chapter covers them in detail.

Common mistakes

  • Typing a table field name in a combo box's Row Source instead of a query, so no IDs are stored.
  • Mismatched link fields in a subform, which show all records or none.
  • A text box named the same as its field (for example a calculated control named Total, in a form where Total is also a field), which causes #Name? or circular errors. Rename the control to txtTotal.
  • Too many controls on one screen. Use tabs or split into forms.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A combo box has Bound Column 1, two columns and widths 0";2". What does the user see and what is stored?

    A zero-width first column hides the ID, but because it is the bound column the ID is what is saved.
  2. 2. Which two properties connect a subform to its main form?

    They pair a field in the main form with a field in the subform so only related records show.
  3. 3. A text box shows =[Quantity]*[UnitPrice]. Is the result stored in the table?

    Controls whose Control Source starts with = display a value but are not bound to a field.
  4. 4. Why prefix control names with txt, cbo and cmd?

    Prefixes keep names readable and prevent a control from sharing a name with its field, which can cause #Name? errors.

Summary

  • Add controls from the Controls gallery or by dragging fields from Add Existing Fields; name them with prefixes.
  • Combo boxes show friendly names while storing keys; set Row Source, Bound Column, Column Count and Column Widths.
  • Subforms show related records and connect through Link Master Fields and Link Child Fields.
  • Controls starting with = calculate; conditional formatting highlights values; command buttons run actions.
  • Use layouts, tab controls and consistent names to keep forms clean.

Next: Creating Reports in Access