Store images in a database

You can display images, such as pictures, logos, and photographs, on your forms and reports. To do so, you first need to store those images. Access provides several ways to store images, and this article explains how to use each method.

If you need information about displaying images on forms and reports, see Use images in your Access forms, reports, and controls. For an overview of some of the ways you can use images with an Access database, see the article Dress up your Access database.

 Tip    Try Office 2010 Access 2010 features enhanced image management, letting you attach images to specific records!
Watch a video or try Office 2010.

About storing images in an Access database

Access 2003 provides several ways to store images. You can:

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

ShowWhat's an OLE Object field?

Object Linking and Embedding (OLE) is the technology used to share files among the various Office programs. For example, when you insert an Excel spreadsheet into a 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 the easiest 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 update the links to your image files.

However, embedding images 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 additional bitmap files that contain display information for each of your image files, and those additional files can be larger than your original images. In addition, this method only supports the Windows Bitmap (.bmp) and Device Independent Bitmap (.dib) graphic file formats. If you want to display other common types of image files, such as GIF and JPEG images, you have to install additional software.

  • Store images on a hard drive or network and link to them from a database table.

This method is similar to the first, but instead of embedding images in an OLE Object field, you link to them. This method is a middle ground. 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, and your links also break if your files become corrupt. In addition, this method supports the same limited number of file types as the first method (Windows Bitmap and Device Independent Bitmap), and it requires additional software to display more file types.

  • Use Visual Basic for Applications (VBA) code to display the images.

This method involves storing images on a hard drive or network, storing the image paths and file names 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 space, and you can use or adapt existing sample code. If you have a large number of images, this is the recommended method.

However, keep in mind that if you move your database, you also have to move the images.

The following sections explain how to use each storage method, and provide links to sample code.

Embed or link to images in a database table

The process of embedding or linking to images in a table follows 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.
  • Insert your image files into the field. During that process, you choose whether you embed or link to the image.

The following sections explain how to perform those tasks.

ShowAdd an OLE Object field to an existing table

  1. Open the table in Design view Button image.
  2. In the first blank row of the design tool, under Field Name, enter Image.
  3. Click the next field (the field in the Data Type column), and select OLE Object from the list.
  4. Save the table.
  5. 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)," later in this section.

ShowCreate a new table containing an OLE Object field

  1. On the Objects bar in the Database window, click Tables, and then double-click Create table in Design view. The table design tool appears.
  2. In the first row of the design tool, under Field Name, enter ID.
  3. Click the first field under Data Type and select AutoNumber from the list.
  4. Right-click anywhere in the first row and click Primary Key. This sets the ID field as the primary key for the table.
  5. In the next row, enter Image in the Field Name column, and select OLE Object from the list in the Data Type column.
  6. Save the table. You can accept the name that Access gives the table, or use another name.
  7. Close the table in Design view, and then open it in Datasheet view (double-click the table to reopen it).
  8. Continue to the next set of steps, "Add images to the OLE Object field (embedded or linked)."

ShowAdd 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. Alternatively, you can use your own tables and image files.

  1. Right-click the first field in the Image column of the table and click Insert Object.
  2. Click Create from File, and then click Browse.
  3. Browse to one or more Windows Bitmap (.bmp) or Device Independent Bitmap (.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 click OK.

This assumes you accepted the default installation path during Setup.

  1. 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 OLE Object field, you're trying to link 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 more information about reinstalling Photo Editor, see What to do when you see "Package" instead of "Bitmap Image" in your database tables.

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

Use VBA code to display images

If you need to work with a large number of image files and you want to display a different image with each database record, using some VBA programming can save you time and storage space. You store your images on your hard drive or network, store the paths and file names of your images in a text field in your database, and then use VBA code to read the path information and set the Picture property of the Access image control.

Keep in mind that this process links to your image files — it does not bind them. Also, if you move your database, you also need to move your images. To see an example of this technique, start the Northwind Traders sample database and open the Employees form in Design view.

  1. Open the table to which you want to add the field in Design view Button image.
  2. In the first blank row of the design tool, under Field Name, enter Image.
  3. Click the next field (the field in the Data Type column), and select Text from the list.
  4. Save the table.
  5. 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\Picture.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\Picture.gif.

Applies to:
Access 2003