Adding Combo and List Boxes

Combo and list boxes both serve the same basic purpose by letting you pick a value from a list, rather than type the value in a text box. These two kinds of lists are especially useful when you need to enter a code that represents the name of a person, firm, or product. You don't need to refer to a paper list of the codes and names to make the entry. The following list describes the differences between combo and list boxes:

  • Combo boxes consume less space than list boxes in the form, but you must open these controls to select a value. You can allow the user to enter a value in the text box element of the drop-down combo list or limit the selection to just the members in the drop-down list. If you limit the choice to members of the drop-down list (sometimes called a pick list), the user can still use the text box to type the beginning of the list value Access searches for a matching entry. This feature reduces the time needed to locate a choice in a long list.

  • List boxes don't need to be opened to display their content; the portion of the list that fits within the size of the list box you assign is visible at all times. Your choice is limited to values included in the list.

In most cases, you bind the combo or list box to a field so that the choice updates the value of this field. Two-column controls often are the most common. The first column contains the code that updates the value of bound field, and the second column contains the name associated with the code. A multiple-column list is most useful when assigning supervisor and manager employee ID numbers to the InitiatedBy and ApprovedBy fields in the frmHRActionEntry form, for example.

Using the Combo Box Wizard

Designing combo boxes is a more complex process than creating an option group, so you're likely to use the Combo Box Wizard for every combo box you add to forms. Follow these steps to use the Combo Box Wizard to create the cboInitiatedBy drop-down list that lets you select from a list of Northwind Traders' employees:

  1. graphics/design_view.gif Open the frmHRActionEntry form (that you created and saved earlier in this chapter) from the Database window in Form Design view if it isn't presently open.

  2. graphics/run.gif Click the Control Wizards button, if necessary, to turn on the wizards.

  3. graphics/combo_box.gif Click the Combo Box tool in the Toolbox. The mouse pointer turns into a combo box symbol while on the active surface of the form.

  4. graphics/field_list.gif Click the Field List button to display the Field List.

  5. Drag the InitiatedBy field to a position at the top and rightmost edge of the form's Detail section, opposite the EmployeeID field (look ahead to Figure 15.26). The first Combo Box Wizard dialog opens.

  6. You want the combo box to look up values in the Employees table, so accept the default option (see Figure 15.22). Your selection specifies Table/Query as the value of the Row Source Type property of the combo box. Click Next.

    Figure 15.22. The first Combo Box Wizard dialog lets you select the type of combo box to create. This example uses a lookup-type combo box.

    graphics/15fig22.gif

  7. In the second Wizard dialog, select Employees from the list of tables (see Figure 15.23), and click Next.

    Figure 15.23. Select the table or query to provide the list items of the combo box in the Wizard's second dialog. Use a base table, Employees for this example, to assure that the list doesn't contain multiple entries for a single lookup value.

    graphics/15fig23.jpg

  8. For this example, the combo box needs the EmployeeID and LastName fields of the Employees table. EmployeeID is the field that provides the value to the bound column of the query, and your combo box displays the LastName field. EmployeeID is selected in the Available Fields list by default, so click the > button to move EmployeeID to the Selected Fields list. LastName is then selected automatically, so click the > button again to move LastName to the Selected Fields list. Your Combo Box Wizard dialog appears as shown in Figure 15.24. This selection generates the Jet SQL SELECT query that serves as the value of the combo box's Row Source property and populates its list. Click Next.

    Figure 15.24. In the third Wizard dialog, add the bound column and one or more additional columns to display in the combo box list.

    graphics/15fig24.jpg

    Tip

    If two or more employees have the same last name, add the FirstName field to the combo list. Unlike conventional combo and list boxes, Access controls can display multiple columns.

  9. graphics/new.gif

    Access 2003 adds a new sorting dialog to the Combo Box Wizard. To sort the list by last name, open the first list and select the LastName field (see Figure 15.25). Selecting a sort on one or more fields adds an ORDER BY clause to the combo box's SELECT query.

  10. The fifth dialog displays the list items for the combo box. Access has successfully determined that the EmployeeID field is the key field of the Employees table and has assumed (correctly) that the EmployeeID field binds the combo box.

    Note

    The Hide Key Column check box is selected by default; this option causes Access to hide the bound column of the combo box. You've selected two columns for the combo box, but only one column (the LastName field) displays in the combo box's list. The EmployeeID column is hidden and used only to supply the data value for the InitiatedBy field.

    Figure 15.25. In the new Wizard sorting dialog, select the field(s) on which to apply an ascending or descending sort. Clicking an Ascending button toggles an Descending or Ascending sort.

    graphics/15fig25.gif

  11. Resize the LastName column by dragging the right edge of the column to the left you want the column wide enough to display everyone's last name but not any wider than absolutely necessary (see Figure 15.26). Click Next.

    Figure 15.26. The Wizard queries the combo box's data source (the Employees table) and displays the control's list items. Double-click the right edge of the list to size the list's width to fit the list items.

    graphics/15fig26.jpg

    Note

    Resizing the list width doesn't accomplish its objective in Access 2003 or the previous two versions. The Wizard adds a combo box of the size you created when dragging the tool on the form, regardless of the width you specify at this point.

  12. Your combo box updates the InitiatedBy field the EmployeeID value corresponding to the name you select. You previously specified that the Control Source property is the InitiatedBy column when you dragged the field symbol to the form in step 5. The Combo Box Wizard uses your previous selection as the default value of the Control Source property (see Figure 15.27), so accept the default by clicking the Next button to display the sixth and final dialog.

    Figure 15.27. The fifth Wizard dialog specifies the column of the query to be updated by the combo box selection.

    graphics/15fig27.jpg

  13. The last dialog lets you edit the label associated with the combo box (see Figure 15.28). Type Initiated by: and click Finish to add the combo box to your form.

    Figure 15.28. Type the label caption for the combo box in the sixth and last Wizard dialog.

    graphics/15fig28.jpg

  14. graphics/bold.gif graphics/properties_window.gif Apply the bold attribute to the combo box label, and adjust the width and position of the label. Open the Properties window for the combo box, and change its name to cboInitiatedBy. Figure 15.29 shows the new combo box in Form Design view.

    Figure 15.29. The Combo Box Wizard sets the property values for the combo box.

    graphics/15fig29.gif

    Note

    The Row Source property is the SQL SELECT statement that fills the combo box's list. Specifying a Column Width value of 0 hides the first column. The Description property of the EmployeeID field provides the default Status Bar Text property value.

  15. graphics/subform.gif Change to Form view to test your combo box. Change the Initiated by value to another person, and then use the navigation buttons to move the record pointer and make the change permanent. Return to the original record, and verify that the combo box is bound to the InitiatedBy field (see Figure 15.30).

    Figure 15.30. The combo box in Form view displays a list with the default maximum of eight items. You can change the depth of the list by specifying a different value for the List Rows property.

    graphics/15fig30.jpg

Jet SQL

The Jet SQL statement generated by the Combo Box Wizard for cboInitiatedBy is

 SELECT Employees.EmployeeID, Employees.LastName FROM Employees ORDER BY [LastName]; 

Tip

If you don't use the Wizard to generate the combo box, you can select an existing table or query to serve as the Row Source for the combo box.


Using the Query Builder to Populate a Combo Box

If the Row Source Type property for a combo box is Table/Query, you can substitute a custom SQL statement for a named table or query as the value of the Row Source property. For either tables or queries, you can choose only the fields or columns you want for the text box, eliminating the need to hide columns. In addition, you can specify a sort order for the list element of your combo box and specify criteria to limit the list.

To invoke Access's Query Builder and create an SQL statement for populating a manually added Approved by combo box, follow these steps:

  1. graphics/run.gif graphics/field_list.gif Return to or open frmHRActionEntry in Design view, and click to disable the Toolbox's Control Wizards button to add the combo box manually. Click the Field List button, if necessary, to display the field list.

  2. graphics/combo_box.gif graphics/properties_window.gif Click the Combo Box button in the Toolbox, and then drag the ApprovedBy field to add a new combo box under the Initiated By combo box you added in the preceding section. Select the new control and open the Properties window if necessary.

  3. graphics/builder.gif Select the Row Source property, and click the Build button to launch the Query Builder. The Query Builder window is identical in most respects to the Query Design window, but its title and behavior differ.

  4. Add the Employees table to the query, and then close the Show Table dialog. Drag the EmployeeID, LastName, and Title fields to the Query Design grid.

  5. You want an ascending sort on the LastName field, so select Ascending in the Sort check box. Only presidents, vice-presidents, managers, and supervisors can approve HR actions, so type Like *President* in the first Criteria row of the grid's Title column, Like *Manager* in the second, and Like *Supervisor* in the third. Access adds the quotation marks surrounding the Like argument for you. Clear the Show check box of the Title column. Your query design appears as shown in Figure 15.31.

    Figure 15.31. This query design limits approval to employees whose titles include President, Manager, or Supervisor.

    graphics/15fig31.jpg

    Tip

    graphics/run_toolbar.gif

    Test the results of your query by clicking the Run button on the toolbar. Access executes the query and displays a Datasheet view of the query's results. For this example, only Mr. Buchanan and Dr. Fuller meet the criteria.

  6. Close the Query Builder. The message box shown in Figure 15.32 appears to confirm your change to the Row Source property value, instead of asking if you want to save your query. Click Yes and the SQL statement derived from the graphical Query Design grid becomes the value of the Row Source property.

    Figure 15.32. This query design supplies the corresponding Jet SQL statement as the value of the combo box's Row Source property.

    graphics/15fig32.gif

  7. In the combo box's Properties window, change the name of the combo box to cboApprovedBy. Change the Column Count property value to 2 and type 0.2;0.8 in the Column Widths text box. You specify column widths in inches, separated by semicolons, Access adds the units double quotes (") for inches to the widths. (Metrified users specify column widths in cm.) Finally, change the Limit to List value to Yes.

    Tip

    You can display only the LastName field in the combo box, making the combo box similar in appearance to that for the InitiatedBy field, by setting the first Column Width value to 0.

  8. graphics/bold.gif Change the label caption to Approved by: and apply the Bold attribute.

  9. graphics/subform.gif Switch to Form view to test the effect of adding the sort (the ORDER BY clause) and criteria (the WHERE clause) to the query (see Figure 15.33). Press Ctrl+S to save your form changes.

Jet SQL

The Jet SQL statement generated by the Query Builder is

 SELECT Employees.EmployeeID, Employees.LastName FROM Employees WHERE (((Employees.Title) Like "*President*")) OR     (Employees.Title) Like "*Manager*") OR     (Employees.Title) Like "*Supervisor*")) ORDER BY Employees.LastName; 

Jet SQL uses the DOS and UNIX * and ? wildcards for all characters and a single character, respectively. T-SQL requires the ANSI SQL wildcards % and _, and surrounds character strings with a single-quote rather than double-quotes. The table name prefixes aren't needed, and the parentheses in the WHERE clause are superfluous.

Figure 15.33. The combo box list contains items for employees whose titles comply with the Like criteria.

graphics/15fig33.gif

T-SQL

The simplified T-SQL equivalent of the preceding Jet SQL statement for ADP is

 SELECT EmployeeID, LastName FROM dbo.Employees WHERE Title LIKE '%President%' OR     Title LIKE '%Manager%' OR     Title LIKE '%Supervisor%' ORDER BY LastName 

The dbo. prefix called the schema component of the table name in the preceding statement is optional, but is a common practice in T-SQL statements.

It's a more common practice for ADP to use SQL Server 2000 views, stored procedures, or table-returning functions to provide the Row Source for forms, combo boxes, and list boxes.

Creating a Combo Box with a List of Static Values

Another application for list boxes and combo boxes is picking values from a static list of options that you create. A drop-down list to choose a Rating value saves space in a form compared with the equivalent control created with option buttons within an option group. As you design more complex forms, you find that display "real estate" becomes increasingly valuable.

The option group you added to the frmHRActionEntry form provides a choice of only 5 of the possible 10 ratings. To add a drop-down list with the Combo Box Wizard to allow entry of all possible values, do the following:

  1. graphics/design_view.gif graphics/run.gif Change to Form Design view, and click the Control Wizards button in the Toolbox to enable the Combo Box Wizard.

  2. graphics/field_list.gif graphics/combo_box.gif Open the Field List window, and then click the Combo Box tool in the Toolbox. Drag the HRRating field symbol to a position underneath the cboApprovedBy combo box you added previously.

  3. In the first Wizard dialog, select the I Will Type in the Values That I Want option (refer to Figure 15.22), and then click Next to open the second dialog.

  4. The Rating combo box requires two columns: The first column contains the allowable values of HRRating, 0 through 9, and the second column contains the corresponding description of each rating code. Type 2 as the number of columns.

  5. Access assigns value-list Row Source property values in column-row sequence; you enter each of the values for the columns in the first row and then do the same for the remaining rows. Type 9 Excellent, 8 Very Good, 7 Good, 6 Average, 5 Acceptable, 4 Marginal, 3 Fair, 2 Sub-par, 1 Poor, 0 Terminated(use the Tab key and don't type the commas).

  6. Set the widths of the columns you want by dragging the edge of each column header button to the left, as shown in Figure 15.34. If you don't want the rating number to appear, drag the left edge of column 1 fully to the left to reduce its width to 0. When you've adjusted the column widths, click Next to open the third dialog.

    Figure 15.34. Type the values for the two columns in the list, and then adjust the column widths to suit the list's contents.

    graphics/15fig34.jpg

  7. Select Col1, the HRRating code, as the bound column for your value list that is, the column containing the value you want to store or use later (see Figure 15.35); this column must contain unique values. Click Next to open the fourth dialog.

    Figure 15.35. Select the column that contains the unique value to identify the rows of the list, in most cases, Col1.

    graphics/15fig35.jpg

  8. Accept the default value (the HRRating column) in the fourth dialog, and click Next to open the final dialog of the Combo Box Wizard.

  9. graphics/bold.gif Type Rating: as the label for the new combo box control, apply the Bold attribute to the label, and then click Finish to complete the combo box specification and return to Form Design view.

  10. graphics/properties_window.gif Open the Properties window for the combo box, change the Name to cboRating, and then click the Data tab in the Properties window. Set Limit to List to Yes to convert the drop-down combo to a drop-down list. Quickly review the Row Source property. Notice that the Wizard has added semicolons between the row entries, and quotation marks to surround the text values in the Row Source property. You use this format when you enter list values manually.

  11. graphics/subform.gif Change to Form view. The open Rating static-value combo box and its Properties window appear as shown in Figure 15.36.

Figure 15.36. The value-list version of the cboRating combo box closely resembles the cboApprovedBy combo box.

graphics/15fig36.gif

Another opportunity to use a static-value combo box is as a substitute for the Type text box. Several kinds of performance reviews exist: Quarterly, Yearly, Bonus, Salary, Commission, and so on, each represented by an initial letter code.

Tip

graphics/align_right.gif

graphics/align_left.gif You can improve the appearance of columns of labels and associated text, list, and combo boxes by right-aligning the text of the labels and left-aligning the text of the boxes. Select all the labels in a column with the mouse, and click the Align Right button on the toolbar. Then select all the boxes and click the Align Left button.


Creating a Combo Box to Find Specific Records

The Combo Box Wizard includes a third type of combo list box that you can create a combo list that locates a record on the form based on a value you select from the list. You can use this type of combo box, for example, to create a Find box on the frmHRActionEntry form that contains a drop-down list of all last names from the Employees table. Thus, you can quickly find HRActions records for employees.

To create a combo box that finds records on the form based on a value you select from a drop-down list, follow these steps:

  1. graphics/run.gif Change to Design view, and click the Control Wizards button in the Toolbox, if necessary, to enable the Combo Box Wizard.

  2. graphics/combo_box.gif Click the Combo Box tool in the Toolbox, and then click and drag on the surface of the form's Detail section to create the new combo box in a position underneath the cboRating combo box you created previously. Release the mouse, and the first Combo Box Wizard dialog appears. When you don't drag a column name to the form, you create an unbound combo box.

  3. Select the Find a Record on My Form Based on the Value I Selected in My Combo Box option, and click Next (refer to Figure 15.22).

  4. In the second Wizard dialog, scroll the Available Fields list until the LastName field is visible. Click to select this field, and then click the > button to move it to the Selected Fields list (see Figure 15.37). Click Next to open the third dialog.

    Figure 15.37. Select the name of the field to search in the Available Fields list, and click > to add the entry to the Selected Fields list.

    graphics/15fig37.jpg

    Tip

    When creating a combo box to find records, select only one field. The combo box won't work for finding records if you select more than one field for the combo box's lists.

    If the record source contains more than one person with the same last name, you need to add a calculated FullName query column to use the find-record combo box version. For this example the expression to create a FullName query column is FullName: [LastName] & ", " & [FirstName].

  5. The Combo Box Wizard now displays a list of the field values from the column you just selected. Double-click the right edge of the LastName column to get the best column-width fit for the data values in the column, and then click Next to go to the fourth and final step of the Wizard.

  6. graphics/bold.gif Type Find: as the label for the new combo box, and then click Finish to complete the new combo box control. After applying the bold attribute to the label and adjusting its size, your form appears as shown in Figure 15.38.

    Figure 15.38. The record-finding version of the combo box uses an event procedure to move the record pointer to the first record matching the combo box selection.

    graphics/15fig38.jpg

    Caution

    Don't change the name of the new combo box at this point. If you change the name at this point, the Find combo box won't work in Form view.

  7. graphics/subform.gif Click the Form View button on the toolbar to display the form. The open Find: combo box appears as shown in Figure 15.39.

  8. Press Ctrl+S to save your work so far.

Figure 15.39. The combo box finds the records for last name Buchanan. If you have more than one record for an employee, multiple instances of the LastName value appear in the list at this point.

graphics/15fig39.gif

Tip

Always use unbound combo box controls for record selection. If you bind a record-selection combo box to a field, the combo box updates field values with its value.


When you create this type of combo box, the Combo Box Wizard automatically creates a VBA event subprocedure for the After Update property of the combo box (refer to the Property window in Figure 15.35). An event subprocedure is a VBA procedure that Access executes automatically whenever a particular event occurs in this case, updating the combo box. Chapter 27, "Learning Visual Basic for Applications," describes how to write Access VBA code and Chapter 28, "Handling Events with VBA 6.0" describes how to write event-handling subprocedures.

graphics/properties_window.gif To view the event procedure code that the Wizard created for your new combo box, change to Design view, open the Properties window for the Name: combo box, click the Events tab in the window, select the After Update property text box, and then click the Build button. Access opens the VBA Editor window shown in Figure 15.40. After you've looked at the code, close the VBA Editor and return to Design view.

Figure 15.40. The Combo Box Wizard generates the Combo37_ AfterUpdate VBA subprocedure to find the record.

graphics/15fig40.jpg

To use a combo box of this type, select a value from the list. As soon as you select the new value, Access updates the combo box's text box, which then invokes the VBA code for the After Update event procedure. The VBA code in the After Update procedure finds the first record in the form's Recordset with a matching value and displays it. You can use this type of combo box only to find the first matching record in a Recordset.

Tip

If you change the name of the combo box to comply with the naming convention mentioned earlier, you must also change the name of the VBA procedure. For example, replace the two instances of Combo37 in the VBA code shown in Figure 15.40 with cboFind, close the VBA code editor, then change the Name property value of the combo box to cboFind, and finally set the After Update event's value to [Event Procedure].

Name AutoCorrect, which is enabled by default in the General Page of the Options dialog, doesn't change the names of VBA event procedures to correspond to changes of object names, or vice-versa.


Because the field on the form is based on the LastName column of the form's underlying query, you see an entry in the list for every last name entry in the Recordset produced by the qryHRActions query. If, for instance, more than one Personnel Action record exists for Steve Buchanan, Buchanan appears in the combo list as many times as there are records for him. If an employee doesn't have a record in the qryHRActions query result set, the name doesn't appear in the list. To display a unique list of all employee last names, change the Row Source property to obtain the LastName field values for the combo box list through an SQL statement based on a query from the Employees table.

graphics/builder.gif To change the Row Source property, follow the procedure you learned in the "Using the Query Builder to Populate a Combo Box" section, earlier in this chapter: Open the Properties window of the Name: combo box, click the Data tab, select the Row Source text box, and then open the Query Builder. Change the query so that it uses the LastName field of the Employees table, add an ascending sort, as shown in Figure 15.41, and change the Limit to List property value to Yes.

Figure 15.41. Changing the Row Source of the combo box to a query against the Employees table eliminates duplicate items in the Find: combo box.

graphics/15fig41.gif

Using Bound Object Frames

Access OLE Object fields let you embed or create a link to graphic images, sound or video files, or any other type of object for which you have an OLE 2.0 server installed and registered on your computer. OLE Object fields are unique to Access, and other applications (such as Visual Basic) can't directly read the data the fields contain. Access adds a special "OLE wrapper" to the data that identifies the OLE 2.0 server used to create and display or play the data.

The tab control that you add later in the chapter includes a bound object frame to display a photo for each employee. To use a bound object frame, you must add a field of the OLE Object type to the Employees table, and then insert the images from the files into the Employees table. The sections that follow describe how to add an OLE Object field to a table, insert objects into the field, and test displaying bitmap objects in a temporary bound object frame.

Note

Storing images in OLE Object fields isn't considered a good database design practice, especially if you expect to handle a large number of images. This isn't an issue, however, with the nine Northwind employee photos that are used in the following example.


Adding an OLE Object Field to the Employees Table

graphics/access_2002_new_icon.gif

The Employees table of early versions of Access used an OLE Object field to hold employee photos, and the Employees form displayed the images in a bound object frame. Access 2002 changed the Photo field to a field of the Text data type, which contains the names of individual bitmap files EmpID1.bmp through EmpID9.bmp stored in the ...\Office10\Samples folder. The Employees form contains VBA code to display the appropriate image in an image control.

Note

Microsoft's objective in substituting linked .bmp files for embedded bitmaps isn't clear. The reason might have been to make the Employees table compatible with SQL Server, which doesn't support OLE Object fields. However, the Categories table has a Picture OLE Object field. Even less clear is the reason for using the .bmp format, which consumes much more storage space than a compressed image format, such as Graphics Interchange Format (.gif) or Joint Photographic (Experts) Group (.jpg).


To add a new OLE Object field to the Employees table, do this:

  1. Close the frmHRActionEntry form and any open queries against the Employees table.

  2. In the Database window, create a backup copy of the Employees table by selecting it, pressing Ctrl+C, and then pressing Ctrl+V. Type a name for the backup, such as Employees_Orig, in the Paste Table As dialog, and click OK.

  3. graphics/design_view.gif Open the Employees table in Design view, and select the Notes field.

  4. Press Insert to add a new field, type PhotoOLE as the field name, and set the Field data type to OLE Object.

  5. graphics/foreign_key.gif Change to Datasheet view, and save your change to the table design.

Embedding or Linking Images in an OLE Object Field

Embedding the object's data is safer than creating an OLE link to the object's source file, because someone might move the source files. Linking the source files doesn't save space in the database, because the OLE Object field stores the last version of the image, called its presentation. Linking assures that modifications to the image's source file appear when you display the image in a bound object frame. This example uses embedded data from the nine sample EmpID?. bmp files, but the process is identical for any file type that has an association with an OLE 2.0 server.

To embed or link the sample bitmap files to the PhotoOLE field, do this:

  1. graphics/foreign_key.gif With the Employees table open in Datasheet view, navigate to the PhotoOLE field of the first record.

  2. Right-click the PhotoOLE cell and choose Insert Object to open a Microsoft Access dialog with an Object Type list, which includes all OLE 2.0 servers registered by your computer (see Figure 15.42).

    Figure 15.42. Right-clicking an OLE Object field and choosing Insert Object opens a dialog with a list of registered OLE 2.0 servers.

    graphics/15fig42.jpg

  3. Select the Create from File option, click Browse, and navigate to the \Program Files\Microsoft Office\Office 11\Samples folder.

  4. Double-click Empid1.bmp in the folder to add the file to the File: Bitmap Image text box (see Figure 15.43). If you want to link, rather than embed, the data, click Link before clicking OK.

    Figure 15.43. Selecting the Create from File option changes the dialog to provide a text box to enter the name of the file to embed or link.

    graphics/15fig43.gif

  5. Move to each of the remaining eight records in succession, repeating steps 2, 3, and 4 to add Empid2.bmp through Empid9.bmp to the PhotoOLE field.

  6. graphics/windows_paint.gif After you've added all nine bitmaps, double-click one of the Bitmap Image cells to display the image in Microsoft Paint (see Figure 15.44).

Figure 15.44. Double-clicking a cell of an OLE Object field opens the object in its OLE 2.0 server, in this case Microsoft Paint.

graphics/15fig44.jpg

Note

If .bmp files are associated with another OLE 2.0 server on your computer, such as Adobe Photoshop, the associated server opens. Microsoft Paint is the default server for .bmp files, if another application hasn't assumed this role.


Displaying OLE Object Bitmaps in a Bound Object Frame

Bound object frames display or play OLE objects in a form, and print bitmap and vector-based images in reports. To add a temporary bound object frame to the frmHRActionEntry form that displays the bitmap objects in the PhotoOLE field of the query, do the following:

  1. graphics/design_view.gif Close the Employees table, if it's open, and open qryHRActions in Query Design view.

  2. Drag the PhotoOLE field from the Employees table to the empty column to the right of the Notes column of the grid. Close and save your changes.

  3. graphics/form_select.gif graphics/field_list.gif Open frmHRActionEntry in Form Design view, and display the Toolbox and Field List.

  4. graphics/bound_object_frame.gif Click the Bound Object Frame control in the Toolbox, and drag the PhotoOLE field from the Field List near the upper right corner of the fraRatings option frame.

  5. Adjust the size of the bound object frame to about 1.5 x 1.7 inches.

  6. graphics/subform.gif Change to Form view, and open the Properties window. The default Size Mode property of the control is Clip, so a cropped image of an employee photo opens in the frame (see Figure 15.45).

    Figure 15.45. When you open a bitmapped or other image in a bound object frame, the default mode is Clip. Clip displays a cropped version of the full-size image.

    graphics/15fig45.gif

    Tip

    If the employee photo doesn't appear in the bound object frame, close the form, save your changes, and reopen it in Form view.

  7. Change the Size Mode property value to Zoom, which sizes the image to fit within the frame but doesn't change its aspect ratio the ratio of width to height (see Figure 15.46). Stretch mode expands both the width and height of the image to fit the frame, which can result in distortion of the image.

    Figure 15.46. Change the Size Mode property value from Clip to Zoom to fit the image within the frame without changing the image's aspect ratio.

    graphics/15fig46.gif

  8. graphics/windows_paint.gif Double-click the image to edit the bitmap in situ with Windows Paint. Paint's menu is grafted to Access's menu, the Paint toolbox opens to the left of the form, an OLE activation border surrounds the Clip mode version of the image, and Paint's palette appears at the bottom of the form (see Figure 15.47).

    Figure 15.47. Activating the image with a double-click enables in-situ editing of the object with the designated OLE 2.0 server.

    graphics/15fig47.gif

  9. Click outside the image to deactivate the object, then right-click the frame, and choose Bitmap Image Object, Open to open the object in a linked instance of Paint. It's usually easier to edit images in the server's window than in the smaller in-situ frame.

  10. To prevent users from activating the image with a double-click, click the Other tab (in the Properties window), and set the Auto Activate property value to Manual.

  11. graphics/subform.gif After you've experimented with the bound object frame, return to Form Design view and delete the frame.

The process for adding a static image to an unbound object frame control is similar to that for a bound object frame. You add the unbound frame to the form, right click the frame, and choose Insert Object to add the static image to the control. Charts you create with the Office Chart Wizard in Chapter 18 display in an unbound object frame, but you also can store copies of static charts in an OLE Object field.



Special Edition Using Microsoft Office Access 2003
Special Edition Using Microsoft Office Access 2003
ISBN: 0789729520
EAN: 2147483647
Year: 2005
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net