[Previous] [Content Page] [Next]

Using OLE Object Fields

The Insert Object dialog box
The Insert Object dialog box with the Create from File option selected.
In Datasheet view you normally can't see the actual OLE objects.
The inserted photo displayed in the frmEmployees form.

Perhaps the least understood of all , the OLE Object data type lets you store files created in other programs such as graphics, Excel spreadsheets, or Word documents. This lesson will give you some practice working with OLE object fields.

  1. Select the tblEmployees table and click the Design button.

    First we need to add an OLE field to this table.

  2. Click the first blank Field Name row and type Photo. Click the Data Type list arrow and select OLE Object from the list.

    You've created an OLE Object field!

  3. Save your changes and then click the View button on the toolbar to display the table in Datasheet view.

    Let's try adding an OLE object to the Maria Wyatt record.

  4. Click in any field for Maria Wyatt, scroll to the right, click in the Photo field for the Maria Wyatt record (using the record selector as a guide), and select Insert » Object from the menu.

    The Insert Object dialog box appears, as shown in figure. You can create and then insert new objects by selecting the Create New option or you can click the Create from File option to insert an existing file. For this exercise, we already created and saved a photo, so you need to select the Create from File option.

  5. Click the Create from File option.

    The Insert Object dialog box displays the Create from File options, as shown in figure. Here you will specify the name and location of the file you want to insert.

  6. Click the Browse button.

    Now you need to find and locate the file you want to insert into your document.

  7. Browse to your Practice folder, then find and double-click the Maria.bmp file.

    The name and location of the Maria.bmp file appears in the File box. Before we close the Insert Object dialog box, there is one more very important option we need to explore the "Link" check box. The "Link" check box determines whether the OLE object is actually embedded within the database or merely linked to it. This is a rather difficult concept for most people you might want to look at table for more on the differences between the two.

    For this exercise, we want to embed the graphic within the database, so we'll leave the Link box unchecked.

  8. Click OK.

    The dialog box closes, and Access embeds the Maria.bmp picture in the Photo field.

    The problem with working with OLE object fields in Datasheet view is that you can't see the actual OLE objects. It's for this reason that you may want to use a form to work with OLE object fields.

  9. Close the tblEmployees table. Click the Forms icon in the Objects bar, click the frmEmployees form, and click the Design button.

    First we need to add the new photo field to the form.

  10. Click the Field List button on the toolbar, if necessary. Click and drag the Photo field anywhere on the form.

    Another way to display the field list is to select View » Field List from the menu.

    Don't worry about where you place the Photo OLE object field or if it covers other fieldswe're not striving for perfection here. As with any other form control, you can move and resize OLE object fields.

    Let's see how the Photo field looks in Form view.

  11. Click the View button on the toolbar to switch to Form view. Click the Next Record Navigation button until you find the record for Maria.

    Yep! There's the picture!

  12. Close the frmEmployees form without saving any changes.

Embedded vs. Linked Objects
Object Type Description

Embedded (Link box not checked)

An embedded object is actually saved within the database. Databases with embedded objects are larger than databases with linked objects. The advantage of using embedded objects is that the objects are actually saved inside the database, so you don't have to worry about any attached files becoming lost or erased.

Linked (Link box checked)

A linked object is not saved in the database. Instead, a link contains information on where to find the source data file. The advantage of using linked objects is that if the source file is changed, the linked object in the database is automatically updated to reflect the changes.


TO CREATE AN OLE OBJECT FIELD:

  1. DISPLAY THE TABLE IN DESIGN VIEW.

  2. CREATE A NEW FIELD TO STORE THE OLE OBJECTS.

  3. CLICK THE NEW OLE FIELD'S DATA TYPE BOX, CLICK THE LIST ARROW, AND SELECT OLE OBJECT.

  4. SAVE THE TABLE.

TO INSERT AN OLE OBJECT:

  1. SELECT THE OLE OBJECT FIELD AND SELECT INSERT » OBJECT FROM THE MENU.

  2. SELECT EITHER:

    CREATE NEW:TO CREATE A NEW OLE OBJECT FILE (YOU MUST SELECT THE TYPE OF FILE YOU WISH TO CREATE).

    CREATE FROM FILE: TO INSERT AN EXISTING FILE.

  3. CLICK OK.

  4. IF YOU SELECTED THE CREATE FROM FILE OPTION, BROWSE TO AND DOUBLE-CLICK THE FILE YOU WANT TO INSERT AND CLICK OK.

[Previous] [Content Page] [Next]