Your employees would like a quick way to look up each others’ business phone numbers. They want to be able to choose an employee’s last name from a list and have Access output the employee’s first name and phone number.
To create this form, follow these steps:
- Open the Employees database.
- Click Forms under Objects in the Database window, click the New button, and then click OK. In Access 2007, click the Create tab and then click Forms Design in the Forms group.
- Click the Combo box control in the Controls toolbox. In Access 2007, click the Design tab under Forms Design Tools and click Combo Box (Form Control) in the Controls group.
- Click and drag in the form where you want to locate the control.
- Click Next.
- Select the Employees table and then click Next.
- Select the Employee ID, Last Name, First Name, and Phone Number fields.
- Click Next.
- Click the drop-down arrow in the first text box and click Last Name.
- Click Next.
- Adjust fields as necessary and then click Next.
- Enter Employee Contact Form and click Finish.
- Click in the Combo Box label control and change the label to Last Name.
- Click the Text Box control in the Controls toolbox (Access 2003) or the Controls group (Access 2007).
- Click and drag to create an unbound text box control below the combo box.
- Change the text box label to First Name.
- Click the Text Box control in the Controls toolbox (Access 2003) or the Controls group (Access 2007).
- Click and drag to create an unbound text control below the first text box.
- Change the text box label to Phone Number (Figure A).
Figure A
- Right-click the combo box and select Properties.
- Click in the On Change property box in the Event tab and select Event Procedure.
- Click the Build button and enter this code (Figure B):
Me.Text19 = Me.Combo17.Column(2) Me.Text21 = Me.Combo17.Column(3)
Figure B
- Add an error handler to the On Change event subroutine.
- Press [Alt] + [Q].
Employees can now use this form to scroll through a list of employees sorted by last name, and Access will immediately fill in the person’s first name and business phone number (Figure C).
Figure C
Miss an Access tip?
Check out the Microsoft Access archive and catch up on other Access tips.
Help users increase productivity by automatically signing up for TechRepublic’s free Microsoft Office Suite newsletter, featuring Word, Excel, and Access tips, delivered each Wednesday.