Microsoft Office Tutorials and References
In Depth Information
Making a Find Box
Making a Find Box
When you’re using a form, you can select a control, press Ctrl+F to display
the Find and Replace dialog box, and jump directly to a record that matches
the value you entered for the selected control. But wouldn’t it be nice to
have a combo box right on the form with the Find button next to it so that
you can locate a record without bringing up a separate dialog box? Access
makes this setup surprisingly easy.
On an Address Book form, for example, you could create a combo box that
lists all the customers in your Address Book. When you choose a customer,
the macro takes you right to that customer’s record.
Follow these steps to create a Find box:
1. With your form open in Design view, click the Combo Box button in
the Controls group on the Design tab of the Ribbon.
2. Click your form where you want the Find box to appear.
The Combo Box Wizard runs, as described in “Running the Combo Box
and List Box wizards,” earlier in this chapter.
3. Choose the option labeled Find a Record on My Form Based on the
Value I Selected in My Combo Box, and click Next.
Access displays a list of the fields in the record source of the form.
4. Choose the field(s) containing the values that the user can choose to
finding a record, and click Next.
If you choose a field that’s unique for each record (such as the OrderID
field for a form that displays orders), the combo box provides a list
of the values for the field, and choosing a value takes you right to the
order. If you choose a field that’s not unique, the combo box displays
a list with duplicate values and finds records unpredictably. You can
choose more than one field — Last Name and First Name, for example.
5. Adjust the width of the column(s) that will appear in the drop-down
menu by dragging the column divider(s), and click Next.
6. Type a name for the combo box control, and click Finish.
The wizard creates the combo box.
7. Switch to Form view by clicking the View button on the toolbar, and
test the control.
It looks something like Figure 3-9.