Вы находитесь на странице: 1из 19

Table of contents

About storing and displaying images


Explains the concepts you must understand in order to use images wisely, such as whether to link or embed images and to use bound
or unbound images. It also briefly explains OLE (the technology that some Access components use to store and display images), lists
supported graphics file formats, and explains why you should use certain file types, such as Windows Bitmap (.bmp) files.

Store images in a database


Explains how to add fields to your database tables and either link to or embed image data in those fields.

Display images on forms, reports, and controls


Explains how to add images that remain fixed as you move through database records and report pages, how to display images that
change with each database record or report page, and how to add background images or watermarks. Also explains how to add images
to buttons, and links you to information about displaying images programmatically by using Visual Basic for Applications (VBA) code.

Update and edit links and images


Explains how to update links to your images, how to display updated images automatically and manually, and how to edit images from
within Access.

Solve common display problems


Explains what to do when you see file names instead of images, and "Package" in your table fields instead of "Bitmap Image." Also
explains how to enable graphics filters.

About storing and displaying images


The process of storing and displaying images — digital photographs, computer graphics, and scanned art — typically follows several
broad steps: First, you decide how you want to store your images. You can link to images stored on a hard drive or network, or you can
make your images an integral part of your database file, a process called embedding.

If you want to display a different image with each database record or report page, you either store links to your images in a database
table, or you store the image files in the table as embedded objects. If you want to display static images, such as corporate logos and
background images, you can store your files outside of your database.

After you decide on a storage method, you place a control capable of displaying an image on your form or report, and then either link or
bind that control to the image or images that you want to display.

If you're new to using images in Access, you need to make informed choices about how you store and display your image files. If you
make the wrong storage choices, you can rapidly inflate the size of your database and cause it to run slowly, or your images can
disappear if you move your database without also moving your images. The following sections provide the background information that
you need to know to store, display, and manage images effectively.

NOTE You can't display images in a datasheet view. The steps in this article apply only to forms, reports, and controls such as
buttons.

About storing images


Access provides several ways to store images. You can:

Embed images directly in an OLE Object field in a database table.

What's an OLE Object field?

OLE is the technology used to share files among the various Microsoft Office programs. For example, when you insert a
Microsoft Excel spreadsheet into a Microsoft Word document, or insert a Microsoft PowerPoint slide into a Microsoft Visio
drawing, you're using OLE. You use an OLE Object field when you need to store images (or links to them) and files from
other Office programs directly in your database.

This method is easier to implement because you use the screens and tools that Access provides. Also, the images become
part of your database and they travel with it. You never need to to update the links to your image files, though you do need
to refresh your embedded images if you update your original files. For more information about updating changed images,
see Update and edit links and images, later in this article.

However, this method can rapidly inflate the size of your database and cause it to run slowly. This is especially true if you
store GIF and JPEG files because OLE creates an additional bitmap file that contains display information for each of your
image files. OLE does that by design. It uses the bitmap images if something goes wrong with your original files. Those
additional files can be larger than your original image and thus bloat your database. Keep in mind that Access databases
have a two-gigabyte size limit. If you have a large number of images, you can reach that limit quickly.

In addition, this method only supports the .bmp and device-independent bitmap (.dib) graphics file formats unless you
install additional software, or use VBA code. For information about the additional software, see the next section, and Solve
common display problems later in this article. For information about using VBA code, see the Microsoft Knowledge Base
article ACC: Reading, Storing, & Writing Binary Large Objects (BLOBs).

Why OLE requires additional software and adds bitmap files

By design, OLE uses components called OLE servers to display most types of graphics files, as well as other types of files
such as Microsoft Excel worksheets or Microsoft PowerPoint slides. In this case, an OLE server is a component provided
by the program used to create the original image or other file. The server renders one or more types of files when you link
to or embed those files.

For example, suppose you use a graphics program to create a GIF or JPEG image, and you display that image in one of
the object frames in Access. The object frames use OLE, and they rely on the originating graphics program to render the
image. Put another way, Access and the object frames do not render the image. The originating graphics program does
that work.

At this point, you need to keep several facts in mind: First, in order to render an image, that originating graphics program
must reside on the same computer as your Access database. If that program fails, or you move the database to a computer
that does not contain the originating program, Access cannot render the image. Second, OLE works around that problem
by creating a .bmp or .dib file for all images and other files that you link or embed by using an OLE control. If you move the
database, or the parent program fails, OLE renders the bitmap image, and you at least see a version of the original file.
Third, those DIB files are often larger than your original image. If you convert your GIF or JPEG files to BMP files, OLE
does not need to create a supporting file, and your database does not grow as quickly, even though BMP files are larger
than GIF or JPEG files. Fourth, you can't predict whether a given program will provide the OLE server needed to render a
given type of file.

Finally, if you use the bound object frame to display images, and you see file names instead of your images, you're missing
the OLE server needed to render that file type. This is a problem with Access 2003. To work around it, you can reinstall a
program called Microsoft Photo Editor, which is available on a Microsoft Office 2000 or Office XP installation CD. For more
information about reinstalling Photo Editor, see Solve common display problems.

Finally, keep in mind that if you want to distribute a database to multiple users, Photo Editor must reside on each client
computer.

Store images on a hard disk or network and link to them from a database table. This method is similar to embedding images in an OLE
Object field, but you instead link to them. This method is a middle ground between embedding images and using VBA programming to
display images. Links don't take up as much space as embedded images, and you can use the screens and tools that Access provides
to implement a solution.

However, if you move your database or your image files, you have to update your links. Those links also break if your
image files become corrupt. In addition, this method supports the same limited number of file types as the first method
(.bmp and .dib files), and it requires OLE servers to display more file types. For more information about updating links, see
Update and edit links and images. For more information about that additional software, see Why OLE requires additional
software and adds bitmap files.

Use VBA code to display the images. This method involves storing images on a hard disk or network, storing the image paths and file names
in a text field in a database table, and using code to set the properties for the Access image control and display images. This method
requires programming, but it uses a very small amount of storage space because text fields are much smaller than OLE Object fields. If
you have a large number of images, this is the method we recommend.

However, keep in mind that if you move your database, you also have to move the images. If the paths to the images
change, you must update that data in your table.

About displaying images


As part of working with images in Access, you need to learn some terminology and know the answers to some key questions:

Do you want to use bound or unbound images? You use bound images when you want to display a different image as you move among the
records in a database or the pages in a report. For example, if you have an Employees database and you want to display a picture of
each employee, you use bound images.

In contrast, unbound images don't change as you move among records and pages. If you want to display a corporate logo
or background image on your forms or reports, use an unbound image.
Do you want to link to an image or embed that image? Linking saves space because Access stores just the link information. An embedded
image is actually inserted in the database itself. This can rapidly increase the size of your database file and possibly cause it to run
slowly, but embedding also ensures that an image is always available.

The following sections explain those options and the best ways to use them.

Understand bound and unbound images

Before you use an image or a set of images in your Access database, you need to decide between using a bound or an unbound
image. If you want your images to change as you move among the records in your database or the pages in a report, you use a bound
image. Bound images typically reside in a table in your database. The table can store links to the images, or it can store the images as
embedded objects. However, remember that embedded images can rapidly increase the size of your database and cause it to run
slowly. For information about why images can bloat your database, see Why OLE requires additional software and adds bitmap files.
For information about storing images in database tables, see Store images in a database.

If you want the image to remain constant as you move between records or pages, you use an unbound image. Unbound images can
reside in your database (if you embed them in your forms or reports), on your hard disk, or on a network.

The decision to use bound or unbound images also determines the type of control that you place on your form or report. If you use
bound images, you use a control called the bound image frame. To display unbound images, you can choose between either the image
control or the unbound object frame, or you can add the image to your form as a background or watermark. For more information about
these controls, see the next section, "Understand object frames and image controls."

Understand object frames and image controls

You can use several different controls to display images. The following table lists three commonly used controls and describes their
best uses.

CONTROL USE BEST USE

Image control Displaying unbound linked or embedded Rendering unbound images (linked or embedded). This control loads faster
images (logos, for example) on a form. than the unbound object frame and it supports more types of graphics files
than either the bound or unbound object frames. For a list of the file types that
you can use with the control, see Supported graphics file formats.
Unbound object Displaying unbound linked or embedded Rendering files from spreadsheet programs, word processing programs, and
frame images, plus other types of files, such as so on.
Microsoft Excel worksheets or Microsoft
Word documents.
Bound object Displaying bound images and other types Rendering images that change as you move through records and pages in
frame of files, such as Excel worksheets or reports.
Word documents.

Understand embedding and linking images

You can embed images in your forms and reports, or you can link to them. When you embed an image, Access makes it a part of your
database file and it is always available for use by the form or report. However, embedding images can increase database size because
Access adds each instance of an embedded image to the database file. For example, if you embed a corporate logo in 20 different
forms and five reports, Access stores that logo 25 times. That redundant storage can rapidly increase the size of your database and
cause it to run slowly. Also, if you change your logo, you have to manually update all 25 instances of it in your database file.

In contrast, linked images reside outside of your database file. You can link to an image located on your hard drive or elsewhere on a
network. Linking to images helps reduce the size of your database file because Access only stores the path to the image. However,
linking can create more work for you. For example, if you move an image, you have to update each of the links to that image. In
addition, your links break if the image file becomes corrupt or your network fails. If you have a stable network or a relatively permanent
place to store your images, linking is a good choice because you can update your images in less time and with less cost, and linking
reduces the size of your database.

Understand the methods for storing and displaying images

Access provides several methods for storing images and displaying them on forms and reports. The method you use can affect the size
of your database and potentially cause it to run slowly.

The following table lists each method and describes its advantages and disadvantages.
METHOD ADVANTAGES DISADVANTAGES

Store your images on your hard Keeps the amount of space used by If you store your images on a network sever and your network
disk or network. Store paths to images to a minimum: You store only fails, your links break. If an image file becomes corrupt, the link
your images in a text field and use path information in a text field. Works breaks.
VBA code to set the Picture with more types of graphics files If you want to try this approach, see the Microsoft Knowledge
property of the Access image (including GIF and JPEG files) than the Base article How to display images from a folder in a form, a
control. other options. report, or a data access page.
NOTE This is the method we
recommend because it uses the
least storage space and supports
a greater number of file types.
Store your images on your hard Eliminates the need for using VBA OLE links take up more space in your database, roughly 460 KB
disk or network. Store links to your programming. You can store your per link. Works with fewer types of graphics files and does not
images in an OLE Object field and images on your hard disk or a network natively support .jpg, .gif, and faxed image (.tiff) files. If you store
use either the image control (for server. your images on a network sever and your network fails, your
unbound images) or the bound links break. If you move your database or your image files, or if
object frame to display the an image file becomes corrupt, the links also break. Finally, OLE
images. limits you to 256 colors.
For information on storing links in For more information about dealing with broken links, see
a table, see Store images in a Update and edit links and images.
database. For more information about OLE Object fields and how using
For information on using the them affects database size, see the section in this article Why
image controls, see Display OLE requires additional software and adds bitmap files, and the
images on forms, reports, and Microsoft Knowledge Base article Why OLE objects cause
controls. databases to grow.
Embed your images in an OLE Eliminates the need for using VBA Can dramatically increase database file size. Works with fewer
Object field and use either the programming, makes the images an types of graphics files, does not natively support .jpg, .gif, and
image control (for unbound integral part of your database, and your .tiff files. Also, if you update the original images, you have to
images) or the bound object frame images can travel with the database. refresh the embedded images. Finally, OLE limits you to 256
to display images. Can provide better image fidelity. colors.
For information on storing links in For more information about OLE Object fields and how using
a table, see Store images in a them affects database size, see Why OLE requires additional
database. software and adds bitmap files, and the Microsoft Knowledge
For information on using the Base article Why OLE objects cause databases to grow.
image controls, see Display
images on forms, reports, and
controls.

Supported graphics file formats

The image control supports a larger set of graphics file types than do the unbound and bound object frames:

Computer Graphics Metafile (.cgm)

CorelDraw (.cdr)

Encapsulated PostScript (.eps)

Graphics Interchange Format (.gif)

Icon (.ico)

Joint Photographic Experts Group (JPEG) (.jpg)

Macintosh PICT (.pict)

Portable Network Graphics (.png)

Windows Bitmap (.bmp)

WordPerfect Graphic (.wpg)

The image control may not support some file types until you enable the graphics filters for those types. To enable the filters, see Enable
graphics filters.

The bound and unbound object frames support only these types of graphics files, unless you install additional software:
Windows Bitmap (.bmp)

Device-independent bitmap (.dib)

To display additional types of image files with these controls, you must install additional programs that support those file types. For
more information about that additional software, see Why OLE requires additional software and adds bitmap files.

Store images in a database


The following sections explain the most common ways to store image data in an Access database. The storage methods work for forms
and reports. The steps use the sample Northwind Traders database, but you can adapt the steps to suit your own databases.

Add images to a table


Access provides two options for adding images to tables: You can embed the images directly or you can add links to the images. Both
processes follow these broad steps:

If you haven't already, add an OLE Object field to an existing table, or create a new table and add an OLE Object field.

Either link to or embed your image files in the field. You choose whether you embed or link to the image.

The following sections explain how to perform those tasks.

Add an OLE Object field to an existing table

In the Database window, select the table, and then click Design .

In the first blank row in Design view, under Field Name, type Image.

Click the next field (the field in the Data Type column), click the arrow that appears, and then click OLE Object in the list.

Save the table.

Close the table in Design view, open it in Datasheet view (double-click the table to reopen it), and go to Add images to the OLE Object field
(embedded or linked).

Create a new table containing an OLE Object field

On the Objects bar in the Database window, click Tables, and then double-click Create table in Design view. The table design tool
appears.

In the first row of the design tool, under Field Name, type ID.

Click the first field under Data Type, click the arrow that appears, and then click AutoNumber in the list.

Right-click anywhere in the first row, and then click Primary Key on the shortcut menu. This sets the ID field as the primary key for the table.

In the next row, type Image in the Field Name column, and select OLE Object from the list in the Data Type column.

Save the table. You can accept the name that Access gives the table or use another name.

Close the table in Design view, open it in Datasheet view (double-click the table to reopen it), and go to Add images to the OLE Object field
(embedded or linked).

Add images to the OLE Object field (embedded or linked)


The steps in this section use the existing or new tables described in the previous sections, plus a set of image files installed by
Microsoft Office 2003. You can use your own tables and image files.

Right-click the first field in the Image column of the table, and then click Insert Object on the shortcut menu.

Select Create from File, and then click Browse.

Browse to one or more .bmp or .dib images. You can find a set of BMP files, named Empid1.bmp through Empid9.bmp, at drive:\Program
Files\Microsoft Office\OFFICE11\SAMPLES. Select the first image and then click OK.

To link to an image, click Link, and then click OK again to complete the process. To embed the image in the table, leave the Link check box
blank and click OK. The words "Bitmap Image" appear in the first field of the Image column in the table.

NOTE If "Package" appears in the OLE Object field, you're trying to link to or embed an unsupported graphics file, such
as a GIF or a JPEG. If you need to display those types of files, you can reinstall Microsoft Photo Editor. For information
about doing so, see Solve common display problems. For information about why you need to reinstall Photo Editor, see
Why OLE requires additional software and adds bitmap files.

Go to the other fields in the Image column and repeat steps 2 through 5 until you've added the desired images.

Configure a table to work with VBA code


If you need to display a large number of image files that change as you move through database records, you can store the paths and
file names of your image files in a text field, and then use VBA code to read the path information and set the Picture property of the
Access image control. While this method involves programming, it saves a lot of space in your database, and it supports a greater
number of file types than the OLE Object field.

This section explains how to add a text field to a table and store path and file name data in that field. This section also links to the
information and sample code needed to implement this method.

On the Objects bar, click Table, select the table to which you want to add the field, and then click Design .

In the first blank row of Design view, under Field Name, type Image.

Click the next field (the field in the Data Type column), click the arrow that appears, and then click Text in the list.

Save the table.

Follow the instructions in this Microsoft Knowledge Base article:

How to display images from a folder in a form, a report, or a data access page

Your database users can view the paths to your image files. Unless you trust all possible users, remove any personal information, such
as your name or the name of your computer, from the file paths. Also, keep in mind that you can use relative paths to refer to pictures.

For example, if you place your database on a network, such as \\ServerName\ShareName\, and store your images in a folder on that
share, such as \\ServerName\ShareName\Pictures, you don't have to specify the entire path.

So, instead of using \\ServerName\ShareName\Pictures\PictureFileName.gif, you can use only the portion of the path that is
different, relative to the location of the current Access file, like this: Pictures\PictureFileName.gif.

Display images on forms, reports, and controls


The following sections explain how to add images to forms, reports, and buttons or other controls. To complete these sections
successfully, you must first know how you want to store your images, and you must also know whether you want to link to your image
files or embed them. If you haven't decided those issues, read the information in About storing and displaying images.

Display unbound images (images that don't change) by using the


image control
To display images that don't change as you move among database records or the pages in a report, you use the image control instead
of the unbound object frame. The image control loads quickly and works with a greater number of graphic file formats. These steps use
the sample Northwind Traders database, but you can apply these steps to your own database, if you wish.

Start Access, open the Northwind Traders sample database, and then display the Database window.

How?

On the Help menu, point to Sample Databases, and then click Northwind Sample Database.

If a Security Warning dialog box appears, click Open.

Click OK to close the Northwind Traders startup screen.

In the Main Switchboard, click Display Database Window.

At this point, you can create a new form or report and then add an image to it, or you can add an image to an existing form or report. The
steps in the following sections explain how to take both actions.

Create a new form and then add an image

On the Objects bar, click Forms, and then double-click Create form in Design view. Access opens a new, blank form, displays
the properties sheet for the form, and displays the Toolbox. If the Toolbox does not appear, on the View menu, click Toolbox.

On the Toolbox, click the Image tool .

Point to the location on the form where you want to display your image, and click once to place the control on the form. The location
that you select marks the upper-left corner of the image control. The Insert Picture dialog box appears, and the properties
sheet displays the properties for the image control.

In the Insert Picture dialog box, browse to the image that you want to display. Select the image, and then click OK.

On the property sheet for the image, click the Format tab, and set the properties for the image. For example, use the PictureType
property box to specify whether you want to embed or link to the image. You can also size or clip the image by clicking the
SizeMode property and selecting one of the following settings.

SETTING DESCRIPTION

Clip Displays the picture at actual size. If the picture is larger than the image control, Access cuts off the image.

Stretch Sizes the picture to fit the image control. Depending on the shape of the image control, this setting may distort the
image.

Zoom Keeps the height and width of the image in correct proportion, regardless of how you size or resize the image control.

NOTE If you need help with a property, select that property and press F1.

Set the other properties, such as visibility and border style, and then click Save to save your changes.

Add any remaining controls, such as lists, text boxes, and subforms, and save your changes. To view the form, either close and

reopen it, or on the Database window, click Open .

Create a new report and add an image

On the Objects bar, click Reports, and then double-click Create report in Design view. Access opens a new, blank report.
On the View menu, click Toolbox.

On the Toolbox, click the Image tool .

Point to the location on the report where you want to display your image, and click once to place the control on the form. You can
place the control in the page header, detail, or page footer sections of the report. The location you select marks the upper-left
corner of the image control. The Insert Picture dialog box appears, and the properties sheet displays the properties for the
image control.

In the Insert Picture dialog box, browse to the image that you want to display. Select the image, and then click OK.

On the property sheet for the image, click the Format tab, and set the properties for the image. For example, use the PictureType
property box to specify whether you want to embed or link to the image. You can also size or clip the image by clicking the
SizeMode property and selecting one of the following settings.

SETTING DESCRIPTION

Clip Displays the picture at actual size. If the picture is larger than the image control, Access cuts off the image.

Stretch Sizes the picture to fit the image control. Depending on the shape of the image control, this setting may distort the
image.

Zoom Keeps the height and width of the image in correct proportion, regardless of how you size or resize the image control.

NOTE If you need help with a property, select that property and press F1.

Set the other properties, such as visibility and border style, and then click Save to save your changes.

Add any remaining fields, such as lists, text boxes, or subreports, and save your changes. To view the report, either close and

reopen it, or on the toolbar, click Preview .

Add an image to an existing form

Start the Northwind Traders sample database, or your own database, and display the Database window.

On the Objects bar, click Forms, select the form that you want to change, and then click Design . Access opens the form in
Design view, displays the properties sheet for the form, and displays the Toolbox. If the Toolbox does not appear, on the View
menu, click Toolbox.

On the Toolbox, click the Image tool .

Point to the location on the form where you want to display your image, and click once to place the control on the form. The location
you select marks the upper-left corner of the image control. The Insert Picture dialog box appears, and the properties sheet
displays the properties for the image control.

In the Insert Picture dialog box, browse to the image that you want to display. Select the image, and then click OK.

On the property sheet for the image, click the Format tab, and set the properties for the image. For example, use the PictureType
property box to specify whether you want to embed or link to the image. You can also size or clip the image by clicking the
SizeMode property and selecting one of the following settings.

SETTING DESCRIPTION

Clip Displays the picture at actual size. If the picture is larger than the image control, Access cuts off the image.
Stretch Sizes the picture to fit the image control. Depending on the shape of the image control, this setting may distort the
image.

Zoom Keeps the height and width of the image in correct proportion, regardless of how you size or resize the image control.

NOTE If you need help with a property, select that property and press F1.

Set the other properties, such as visibility and border style, and then click Save to save your changes. To view the form, either

close and reopen the form, or on the Database window, click Open .

Add an image to an existing report

Start the Northwind Traders sample database, or your own database, and display the Database window.

On the Objects bar, click Reports, select the report that you want to change, and then click Design . Access opens the report
in Design view and displays the Toolbox. If the Toolbox does not appear, on the View menu, click Toolbox.

As needed, move the fields in your report to make room for the image.

On the Toolbox, click the Image tool .

Point to the location on the report where you want to display your image, and click once to place the control on the form. The
location you select marks the upper-left corner of the image control. The Insert Picture dialog box appears, and the properties
sheet displays the properties for the image control.

In the Insert Picture dialog box, browse to the image that you want to display. Select the image, and then click OK.

On the property sheet for the image, click the Format tab, and set the properties for the image. For example, use the PictureType
property box to specify whether you want to embed or link to the image. You can also size or clip the image by clicking the
SizeMode property and selecting one of the following settings.

SETTING DESCRIPTION

Clip Displays the picture at actual size. If the picture is larger than the image control, Access cuts off the image.

Stretch Sizes the picture to fit the image control. Depending on the shape of the image control, this setting may distort the
image.

Zoom Keeps the height and width of the image in correct proportion, regardless of how you size or resize the image control.

NOTE If you need help with a property, select that property and press F1.

Set the other properties, such as visibility and border style, and then click Save to save your changes. To view the report, close

it, and then click either double-click the report, or click Preview .

Add a logo or background image (a watermark) to a form or report


When you add a background image or watermark, the other controls on your form sit on top of the image. For an example of a
background image on a form, start the Northwind Traders sample database and open the Customers form.

Open the form or report that you want to change in Design view.

How?

In the Database window, select the form or report to which you want to add a background image, and then click Design

. Access opens the form or report in Design view.

Double-click the form selector or the report selector to open the property sheet for the form or report.

On the Format tab, in the Picture property box, click the Build button and use the Insert Picture dialog box to locate your image.

In the PictureType property box, specify whether you want to embed the image or link to the image.

After you add the image to the form, click the SizeMode property and select one of the following values.

SETTING DESCRIPTION

Clip Displays the picture at actual size. If the picture is larger than your form window, Access cuts off the image.

Stretch Sizes the picture to fit the form window. This setting may distort the image.

Zoom Maintains the correct proportionality of the image regardless of how you size the from. This setting won't clip the picture or
distort its proportions.

NOTE If you need help with a property, select that property and press F1.

If you want to change the alignment of the picture, click one of the settings in the PictureAlignment property box.

NOTE If you want to center the background picture on a form or report, and you want the background picture to resize
when you size the form or report window, click the Center setting. If you don't want the background picture to resize when
you size the window, click the Form Center setting.

If you want to tile (repeat) the picture across the background of the form or report, set the PictureTiling property to Yes, and set the
SizeMode property to Clip. Tiling starts at the position that is specified for the PictureAlignment property.

NOTE The background picture will not tile if you set the SizeMode property to Zoom or Stretch.

Display bound images (images that change with each database record
or report page)
Access provides a number of ways to display bound images — images that change as you move through the records in a database or
the pages in a report. You can:

Embed your images in a database table and display them by using the bound object frame. This method consumes the most space, but if
your database needs to travel, it ensures that your images are always available.

Store links to your images in a database table and use the bound object frame to display them. This requires less space, but if your images
move or become corrupt, the links break.

In addition, these first two methods require you to store your image data in an OLE Object field. That limits you to using
.bmp or .dib files, unless you want to install additional software. However, these first two methods are easier to implement
because you can use the tools and screens that Access provides.
NOTE You can use VBA code to programmatically store GIF and JPEG files in an OLE Object field, and then display
those files in the image control. For more information, see Add changing images programmatically.

Use VBA code to programmatically set properties for the image control. This method uses a minimal amount of space because you only store
image file names and path information in a text field in one of your tables. It also supports more types of graphics files because you use
the image control instead of the bound object frame. However, keep in mind that implementing this solution requires some programming
experience.

The following sections explain the most common ways to use each method.

NOTE Several of the following sections require a database table that contains an OLE Object field and .bmp or .dib files linked to or
embedded in that field. If you don't have a table with images stored that way, follow the steps in the next section, "Configure a table to
store image data."

Configure a table to store image data

These steps explain how to either add an OLE Object field to an existing table or create a new table with an OLE Object field, and then
either link to or embed images in the OLE Object field.

To add an OLE Object field to an existing table

On the Objects bar in the Database window, click Tables, select the table to which you want to add an OLE Object field, and then click

Design to open the table in Design view. The table design tool appears.

In the first blank row in the design tool, under Field Name, type Image.

In the same row, under Data Type, click the cell, click the arrow that appears, and then click OLE Object in the list.

Save the table. You can accept the name that Access gives the table or use another name.

Close the table in Design view, open it in Datasheet view (double-click the table to reopen it), and go to "To bind the image control to the
table," later in this section.

To create a new table

On the Objects bar in the Database window, click Tables, and then double-click Create table in Design view. The table design tool
appears.

In the first row of the design tool, under Field Name, type ID.

Click the first field under Data Type, click the arrow that appears, and then click AutoNumber in the list.

Right-click anywhere in the first row, and then click Primary Key on the shortcut menu. This sets the ID field as the primary key for the table.

In the next row, type Image in the Field Name column, and select OLE Object from the list in the Data Type column.

Save the table. You can accept the name that Access gives the table or use another name.

Close the table in Design view, open it in Datasheet view (double-click the table to reopen it), and go to the next set of steps.

To add images to the table

Right-click the first field in the Image column of the table, and then click Insert Object on the shortcut menu.

Select Create from File, and then click Browse.

Navigate to one or more .bmp images. You can find a set at drive:\Program Files\Microsoft Office\OFFICE11\SAMPLES. The images are
named EMPID1.BMP through EMPID9.BMP. Select the first image and click OK.

To link to an image, click Link, and then click OK again to complete the process. To embed the image in the table, leave the Link check box
blank and click OK. The words Bitmap Image appear in the first field of the Images column in the table.
NOTE If "Package" appears in the field, this means that you are trying to link to or embed an unsupported graphics file
type. The bound and unbound object frames only support .bmp and .dib files, unless you install other software that enables
the frame to support additional file types. For more information about using the object frames with other file formats, see
Why OLE requires additional software and adds bitmap files. For ways to work around the package problem, see Solve
common display problems.

Go to the second field in the Image column and repeat steps 2 through 5 until you've linked the table to a set of images.

Use the Form Wizard to create a new form that displays images

The Access Form Wizard provides a faster, easier way to create a form and display images that correspond to individual database
records. These steps use the Northwind Traders sample database, but you can use your own database and adapt these steps to fit
your needs.

Start the Northwind Traders sample database and display the Database window.

How?

On the Help menu, point to Sample Databases, and then click Northwind Sample Database.

If a Security Warning dialog box appears, click Open.

Click OK to close the Northwind Traders startup screen.

In the Main Switchboard, click Display Database Window.

On the Objects bar, click Forms, and then double-click Create form by using wizard.

On the first page of the wizard, select the table that contains your image data. Move the OLE Object field (the field containing your image
data) from Available Fields to Selected Fields, and then click Next.

Repeat the previous step as needed to add any remaining fields to your form.

Use the remaining pages in the wizard to select a layout, style, and name for your form, and then click Finish.

Access creates the form, adds a bound object frame to the form, binds the frame to the OLE Object field in the table, and opens the
form for viewing. The images change as you navigate through the records.

Use the Report Wizard to create a new report that displays images

The Access Report Wizard provides a faster, easier way to create a report and display images that correspond to individual report
pages. These steps use the Northwind Traders sample database, but you can use your own database and adapt these steps to fit your
needs.

Start the Northwind Traders sample database and display the Database window.

How?

On the Help menu, point to Sample Databases, and then click Northwind Sample Database.

If a Security Warning dialog box appears, click Open.

Click OK to close the Northwind Traders startup screen.

In the Main Switchboard, click Display Database Window.

On the Objects bar, click Reports, and then double-click Create report by using wizard.

On the first page of the wizard, select the table or query that provides your image data. Move the OLE Object field (the field containing your
image data) from Available Fields to Selected Fields, and then click Next.
Repeat the previous step as needed to move add the remaining fields to your report.

Use the remaining pages in the wizard to select a layout, style, and name for your report, and then click Finish.

Access creates the report, adds a bound object frame to it, binds the frame to the OLE Object field in the table, and opens the report for
viewing. The images change as you navigate through the pages.

Manually create a form that displays changing images

If you do not have a database table with an OLE Object field and image data stored in that field, follow the steps in "Configure a table to store
image data," earlier in this section.

In the Database window, click Forms, and then double-click Create form in Design view. Access creates a new, blank form. The Toolbox
and the property sheet for the new form appear.

On the property sheet for the new form, click the Data tab, click the Record Source property, and then select the table that contains your

images. The Field list appears .

Drag the OLE Object field that contains your images from the Field list to your form. Position the upper-left corner of the icon where you want
the images to appear, and release the mouse button.

Save the form, and then close and reopen the form to view it.

Manually create a report that displays changing images

If you do not have a database table with an OLE Object field and image data stored in that field, follow the steps in "Configure a table to store
image data," earlier in this section.

In the Database window, click Reports, and then double-click Create report in Design view. Access creates a new, blank report.

Double-click the report selector to start the property sheet for the report.

On the property sheet, click the Data tab, click the Record Source property, and then select the table that contains your images. The Field

list appears .

Drag the OLE Object field that contains your images from the Field list to your report. Position the upper-left corner of the icon where you
want the images to appear, and release the mouse button. This automatically places a bound object frame on the report, and you can
place the frame in any section of the report.

Add the remaining fields to your report, save it, and then close and reopen it to view it.

Add changing images to an existing form

Typically, the process of adding changing images to an existing form follows these broad steps:

If necessary, add an OLE Object field to the table from which the form takes its data. You then either add links to your images, or embed your
images in that field. For information about adding an OLE Object field, see "Configure a table to store image data," earlier in this article.

If your form uses a query as its record source instead of a table, you add the OLE Object field to the appropriate table, add images to the
field, and then alter the query to retrieve the images.

How do I alter a query?

NOTE The process of altering queries varies with the type and complexity of the query. For that reason, these steps
explain the basic process for adding a field to a query. For more information about creating and changing queries, see the
links at the end of this section.
In the Database window, on the Objects bar, click Queries, select the query that you want to change, and then click Design to
open the query in the query design grid.

On the toolbar, click Show Table .

In the Show Table dialog box, click the Tables tab, select the table that contains your image data, click Add, and then click Close.

In the query design grid, locate and double-click the field that contains your image data. The new field should appear in the design
grid. The following figure illustrates the field in a sample query that returns image data.

Click Save to save the query.

Help! I need more information!

For more information about creating and changing queries, see the following articles on Microsoft Office Online:

Add or remove a field in the design grid (MDB)

Add or remove a table or query in the query design grid (MDB)

Once you finish altering your data source, you add a bound object frame to your form or report and bind the frame to the table or query.

How?

In the Database window, on the Objects bar, click either Forms or Reports, select the form or report that you want to change, and

then click Design . The Field list appears .

Drag the OLE Object field that contains your image data from the list to your form or report. Position the upper-left corner of the icon
where you want the images to appear, and release the mouse button.

Save the form or report, and then click Open (for a form) or Preview (for a report) to view your changes.

NOTE If you want to store the locations of your image files in a text field, the method that you use to display your images
requires VBA programming. For more information about that method, see the next section, "Add changing images
programmatically."
Add changing images programmatically

NOTE The link in this section takes you to sample code that sets the Picture property of the Access image control.

This is the recommended technique for storing and displaying bound images because it supports more types of graphics files and uses
the least amount of storage space.

To use this technique, you store the paths and file names of your your images in a text field in a table. For information about adding a
text field to a table and for the instructions and sample code needed to use this method, see Configure a table to work with VBA code
earlier in this article.

After you complete that task, you use VBA code to set the Picture property of the image control and display the image. For an example
of this technique at work, start the Northwind sample database and open the Employees form. For information and sample code that
you can adapt, see the Microsoft Knowledge Base article How to display images from a folder in a form, a report, or a data access
page.

NOTE You can programmatically read GIF and JPEG data into an OLE Object field, and then set the Picture property of the image
control. Remember that doing so will consume a lot of storage space. For information and sample code, see the Microsoft Knowledge
Base article ACC: Reading, Storing, & Writing Binary Large Objects (BLOBs).

Add an image to a button or other control


Using an image instead of a text label on a command button or other control can help a user complete a task in less time. Images and
icons can transcend language barriers, and they can often convey the meaning or implication of performing a task more effectively than
a text caption.

Open the form or report in Design view.

How?

On the Database window, select the form or report that you want to open, and then click Design .

Click the command button or toggle button to which you want to add the image, and then click Properties on the toolbar to open its
property sheet. You can also right-click the command or button, and then click Properties on the shortcut menu.

Click the Format tab, and in the Picture property box, type the path and file name for a .bmp, .ico, or .dib file. If you're not sure of the path or

file name, click the Build button to open Picture Builder.

Select an image from the list in Picture Builder, or click Browse to locate another image. If you select an image from the list in Picture
Builder, click OK. If you browse first, locate and select the image, click Open, and then click OK.

NOTE When you add an image to button or command, the image replaces any text labels or captions.

Tip

If the image doesn't look right after you follow these steps, try this workaround: Add an unbound object frame to your form or report at
the location of the button, and then embed your image in the frame. Make sure that your image is the same size as the button, and then
place a transparent button over the image.

Update and edit links and images


If you link to images and then change the location of your database or your images, you must update those links. The following sections
explain how to update links to images in bound and unbound object frames, links to background images, and links to images displayed
by using the image control.

In addition, these sections also explain how to edit images from within Access. If you display images by using an image control, and the
graphics program used to create those images resides on the same computer as your database, you can start that program from within
Access and edit your images.

Update a link to an image in a bound or unbound object frame

Do one of the following:


To update unbound images, in the Database window, select the form or report that contains the unbound object frame, and then

click Design .

To update bound images, open the form or report for viewing (or open the underlying table in Datasheet view), find the image link
that you want to change, and click it.

On the Edit menu, click OLE/DDE Links.

In the Links dialog box, click the link that you want to reconnect or change.

Click Change Source.

In the Change Source dialog box, select the new file name. You may need to switch to a different drive or folder or both to find the
appropriate file.

Click Open to complete the link and close the Change Source dialog box, and then click Close in the Links dialog box.

NOTE When you change a link for a bound object frame, you change the link only for the current record. To make a change in a
different record, move to that record and repeat the process.

Update a link to a background image or to a picture rendered by using the image control

In the Database window, select the form or report that contains the background image or image control, and then click Design .

To start the property sheet, do one of the following:

In a form or report, double-click the form selector or report selector .

For the image control, right-click the control, and then click Properties on the shortcut menu. Or you can click Properties on
the Report Design toolbar.

In the Picture property box, specify the correct path to the image.

Edit images from within Access


If the computer that runs your database has the graphics program used to create your images, and that graphics program supports
being started from within Access, you can edit images directly from your form. If you aren't sure whether your graphics program
supports that functionality, the best way to find out is to follow the steps in these sections and try to edit a bound or unbound image.

NOTE If you're editing embedded images, these steps only change one instance of the image. These steps do not change the original
image. Also, if you embed an image more than once, you must change each instance of the embedded file.

Edit an unbound image

In the Database window, select the form that contains the image control, and then click Design .

Double-click the object.

Access opens the program used to create the image (the OLE server (OLE server: An application or DLL that supplies a linked or embedded
OLE object to another application. For example, if an OLE object in an Access database contains a Microsoft Excel worksheet, Excel is
the OLE server.) application) if that program is available.

NOTE When you double-click a sound or video object, Access plays the object. To open these types of objects for editing,
click the object, and then click the appropriate Object command on the Edit menu. For example, point to the Media Clip
Object command, and then click the Open or Edit command.
Make the changes you want and then do one of the following:

If you're editing the object in place, click the form outside the unbound object frame. Do not click Exit on the File menu, or you'll
exit Access entirely.

If you're editing the object in a separate window, click Exit on the File menu of the graphics program. If you're prompted to update
the image, click OK.

Edit a bound image on a form or in a datasheet

Open the form in Form view, or open a datasheet (datasheet: Data from a table, form, query, view, or stored procedure that is displayed in a
row-and-column format.).

Go to the record that contains the object that you want to edit, and then double-click the object.

Access opens the graphics program used to create the image (the OLE server (OLE server: An application or DLL that
supplies a linked or embedded OLE object to another application. For example, if an OLE object in an Access database
contains a Microsoft Excel worksheet, Excel is the OLE server.) application) if that program is available. The application
may open in a separate window, or you may be able to edit the object in place (in-place activation: Activation of an OLE
object's OLE server from within a field or control. For example, you can play a waveform audio (.wav) file contained in a
control by double-clicking the control.).

NOTE When you double-click a sound or video object, Access plays the object. To open these types of objects for editing,
click the object, and then click the appropriate Object command on the Edit menu. For example, point to the Media Clip
Object command, and then click the Open or Edit command.

Make the changes that you want, and then do one of the following:

If you're editing in place on a form, click the form outside the bound object frame. If you click Exit on the File menu, you'll exit
Access.

If you're editing in a separate window, click Exit on the File menu of the graphics program. If you're prompted to update the
image, click OK.

Control how an image is activated for editing

In the Database window, select the form, and then click Design .

Right-click the object frame (bound or unbound), and then click Properties on the shortcut menu. Or you can click Properties on the toolbar

Do one or more of the following:

To specify whether you activate the object by double-clicking it or by selecting it, set the AutoActivate property. For more
information, click the AutoActivate property box and press F1.

To specify whether you edit the object in place (in-place activation: Activation of an OLE object's OLE server from within a
field or control. For example, you can play a waveform audio (.wav) file contained in a control by double-clicking the
control.) or in a separate window, set the Verb property. For more information, click the Verb property box and press F1.

Make images read-only


To prevent users from editing your images, you can:

Lock the bound or unbound object frame. This prevents users from starting the graphics program used to create an image.

Convert an unbound object frame to an image control, which also prevents users from starting the graphics program used to create an
image.
Lock a bound or unbound object frame

In the Database window, select the form or report, and then click Design .

If the property sheet for the object frame doesn't appear, right-click the frame, and then click Properties on the shortcut menu. Or you can

click Properties on the Form Design or Report Design toolbar.

Set the Locked property to Yes and the Enabled property to No.

Convert an unbound object frame to an image control

In the Database window, select the form or report that contains the object frame, and then click Design .

Click the object frame.

On the Format menu, point to Change To, and then click Image.

Click Yes to confirm the change.

Access converts the unbound object frame to an image control. The object remains on the form, but you can't open the
application that was used to create the image from the form. If you used the frame to run a sound file, just the icon remains.
If you used the frame to display a video file, just the first frame of the video remains, and you can't play the sound or video
file.

Update changed images


When you link to an image and then you change that image, under certain conditions you can specify whether the changed image
appears automatically or only when you request it. The following table lists the common image controls and describes what you need to
do to see updated images.

CONTROL DEFAULT BEHAVIOR TO CHANGE THE BEHAVIOR

Image control Changes appear when you open the form that N/A. Changes appear whenever you open the form that contains the
contains the control. control.

Bound object frame Changes appear when you open the form In
that
the Database window, select the form containing the control, and then click
contains the control.
Design .

Right-click the control, and then click Properties on the shortcut menu to
display the property sheet for the control.

Change the Update Options property from Automatic to Manual.

After you change that property, you must click the image or the control
to see any changes.
Unbound object Displays the image as it was originally In the Database window, select the form containing the control, and then click
frame inserted, regardless of changes.
Design .

Right-click the control, and then click Properties on the shortcut menu to
display the property sheet for the control.

Change the Locked property from Yes to No.

When you change that property, your images update automatically when
you open the form that contains the control.
Delete images
If you can add an image to a form or control, you can remove that image. The following sections explain how.

Delete an image from an object frame or image control

You follow a different procedure for deleting unbound and bound images.

To delete unbound images

In the Database window, select the form that contains the image control or unbound object frame, and then click Design .

Click the control or frame, and then press DELETE.

To delete bound images

Open the form that contains the bound image frame in Form view (Form view: A view that displays a form to show or accept data. Form view
is the primary means of adding and modifying data in tables. You can also change the design of a form in this view.) (or open a
datasheet).

Find the record that you want to change, click the image (or the frame, if it is visible), and then press DELETE.

Access removes the image from the frame and the image data from underlying record source, but the object frame remains on the form. To
delete the frame, open the form or report in Design view, click the control, and then press DELETE.

If you delete the object frame before you delete an image, that image still resides in the underlying table. If you want to
remove the image data, open the table in Design view and then either delete the individual image or delete the OLE Object
field that contains the images.

Delete a background image

In the Database window, select the form, and then click Design .

Double-click the form or report selector to open the property sheet.

Clear the Picture property box.

Delete an image from a button or other control

In the Database window, select the form, and then clickDesign .

Right-click the button that contains the image, and then click Properties on the shortcut menu to start the property sheet for that control.

Clear the Picture property box, and then click any other field in the property sheet to commit the change. When asked to confirm the
deletion, click Yes.

Solve common display problems

Вам также может понравиться