Attach files and graphics to the records in your database

You use the Attachment feature in Microsoft Office Access 2007 to add one or more pieces of data  — Microsoft Office Word 2007 documents, Microsoft Office PowerPoint 2007 presentations, images, and so on — to the records in your database. This article provides the background information and steps needed to configure a database to use attachments, and to attach and manage data.

In this article


Why should I use attachments?

You can use attachments to store several files in a single field, and you can even store multiple types of files in that field. For example, let's say you own a job contacts database. You can now attach one or more resumes to the record for each contact, plus a photo of each contact.

Attachments also store data more efficiently. Earlier versions of Access used a technology called Object Linking and Embedding (OLE) to store images and documents. By default, OLE created a bitmap equivalent of the image or document. Those bitmap files could become quite large — as much as 10 times larger than the original file. When you viewed an image or a document from your database, OLE showed you the bitmap image, not the original file. By using attachments, you open documents and other non-image files in their parent programs, so from within Access, you can search and edit those files.

In addition, OLE requires programs called OLE servers to function. For example, if you store JPEG image files in an Access database, every computer that runs that database requires another program that is registered as an OLE server for JPEG images. In contrast, Office Access 2007 stores the attached files in their native formats with no supporting images, and you do not need to install additional software in order to view the images from within your database.

Attachments and database design rules

By default, each field in a relational database contains only one piece of data. For example, if an address field contained more than one address, finding addresses would be difficult, if not impossible. So at first glance, attachments seem to break the rules of database design because you can attach more than one file — one piece of data — to a field. However, attachments do not break any design rules, because as you attach files to a record, Office Access 2007 creates one or more system tables and uses those tables behind the scenes to normalize your data. You cannot view or work with those tables.

For information about viewing other system tables, see the article Guide to the Navigation Pane. For information about database design, see the article Database design basics.

Ways that you can use attached files

Remember these guidelines as you work with attached files:

  • You can attach files only to databases that you create in Office Access 2007 and that use the new .accdb file format. You cannot share attachments between a Office Access 2007 (.accdb) database and a database in the earlier (.mdb) file format.
  • You must create a field in a table and set that field to the Attachments data type. After you set the data type to Attachments, you cannot change it.
  • You can store multiple files in a single record. For example, you can store images, and files created with word processing and spreadsheet programs.
  • You can attach a maximum of two gigabytes of data (the maximum size for an Access database). Individual files cannot exceed 256 megabytes in size.
  • You use the Attachments dialog box to add, edit, and manage attachments. You can open the dialog box directly from the attachment field in a table by double-clicking the field. If you want to manage attachments from a form or view attachments from a report, you add the attachment control to the form or report and then bind the control to the underlying attachment table field.
  • By default, the attachment control renders images and displays the program icon that corresponds to other file types. For example, let's say you have a photo, a resume, and a Microsoft Office Visio 2007 drawing attached to a record. When you scroll through the attachments, the control renders the image and displays the program icons for the document and the drawing.
  • When you open the Attachments dialog box from a table or a form, you can add, remove, edit, and save attached files. When you open the Attachments dialog box from a report, you can save the attached files only to another location.
  • Access will compress your attached files unless those files are compressed natively. For example, JPEG files are compressed by the graphics program that created them, so Access does not compress them.
  • If the program that was used to create the attached file is installed on your computer, you can open and edit the attached files in that program.
  • You can save the attached files to locations on your hard disk drive or on the network. Then you can edit the attachments and make sure that you like your changes before you save those changes back to your database.
  • You can manipulate attachments programmatically.

The steps in the following sections explain how to add and manage attachments.

Top of Page Top of Page

Add an attachment field to a table

To use attachments in Office Access 2007, you must first add an attachment field to at least one of the tables in your database. Office Access 2007 provides two ways to add an attachment field to a table. You can add the field in Datasheet view, or you can add it in Design view. The steps in this section explain how to use both techniques.

Add an attachment field in Datasheet view

  1. With the table open in Datasheet view, click the first available blank column. To find a blank column, look for the words Add New Field in the column header.
  2. On the Datasheet tab, in the Data Type & Formatting group, click the down arrow next to Data Type, and then click Attachment.

Access sets the data type for the field to Attachment, and places an icon in the header row of the field. The following figure shows a new Attachment field. Note the paperclip icon in the header row of the field. By default, you cannot enter text in the header row of Attachment fields.

A new table field set to the Attachment data type

  1. Save your changes.

Remember that you cannot convert the new field to another data type, but you can delete the field if you think you made an error.

Add an attachment field in Design view

  1. In the Navigation Pane, right-click the table that you want to change and click Design View Button image on the shortcut menu.
  2. In the Field Name column, select a blank row and enter a name for your Attachment field.
  3. In the same row, under Data Type, click Attachment.
  4. Save your changes.

Remember that you cannot convert the new field to another data type, but you can delete the field if you think you made an error.

  1. On the Design tab, in the Views group, click the arrow beneath the View button, and then click Datasheet View to open the table for use.

Access Ribbon Image

-or-

Right-click the document tab for the table and click Datasheet View on the shortcut menu.

-or-

In the Navigation Pane, right-click the table and click Open on the shortcut menu.

  1. Go on to the next steps.

Top of Page Top of Page

Attach files directly to tables

After you add an attachment field to a table, you can attach the files to the records in that table without having to create a data-entry form. You can also view attachments without using a form, but remember that when you view attachments directly from tables, you must do so in the programs that were used to create the files, or in a program that supports that type of file. For example, if you open a Word document that is attached to a table, Word also starts and you view the document from within Word, not Access. If Word is not installed on your computer, a dialog box appears and asks you to select a program for viewing the file.

Add an attachment to a table

  1. With the table that contains your attachment field open in Datasheet view, double-click the attachment field.

The Attachments dialog box appears. The following figure shows the dialog box.

The Attachments dialog box

  1. Click Add.

The Choose File dialog box appears.

  1. Use the Look in list to navigate to the file or files that you want to attach to the record, select the file or files, and then click Open.

You can select multiple files of any supported data type. For a list of supported data types, see Attachments reference later in this article.

  1. In the Attachments dialog box, click OK to add the files to your table.

Access adds the files to the field and increments the number that indicates attachments accordingly. The following figure shows a field with two images attached:

An Attachment field with two pieces of data

  1. Repeat these steps as needed to add files to the current field or other fields in your table.

Open the attached files from a table

  1. With the table open in Datasheet view, double-click the cell in the attachment field.
  2. In the Attachments dialog box, double-click the file that you want to open.

–or–

Select the file and click Open.

The program associated with the file starts and opens the attached file — Excel files open in Excel, and so on.

 Note   Some image files may open in the Microsoft Windows Picture and Fax Viewer. If you want to do more than view the image, you can right-click the image and then click Edit. This starts the program that was used to create the file, if you have that program installed on your computer.

Save changes to an attached file

  1. As needed, use the parent program to edit your file.
  2. Save any changes to the file and close the parent program. Keep in mind that whenever you change an attached file, your changes are saved to the temporary Internet folder on your hard disk drive. See the notes at the end of this section for more information about that folder.
  3. To save your changes permanently, return to Access and, in the Attachments dialog box, click OK.

A message similar to the following appears:

A prompt to save the changes made to an attachment

  1. Click Yes to save your changes.

 Notes 

  • When you open an attached file in its parent program for viewing or editing, Access places a temporary copy of the file in a temporary folder. If you change the file and save your changes from within the parent program, Access saves your changes to the temporary copy. When you return to Access and click OK to close the Attachments dialog box, Access prompts you to save the attached file again. Click Yes to write the changed file to your database, or click No to leave the file untouched in your database.
  • To find the location of your temporary file folder, follow these steps:
    1. Start Windows Internet Explorer.
    2. On the Tools menu, click Internet Options.
    3. On the General tab, click Settings.

The Settings dialog box appears. The folder path appears in the Temporary Internet Files folder section.

Top of Page Top of Page

Use attachments with forms and reports

When you need to use attachments with a form or report, you use the attachment control. The control renders image files automatically as you move among the records in a database. If you attach other types of files, such as documents or drawings, the attachment control displays the icon that corresponds to the file type. For example, you see the PowerPoint icon when you attach a presentation, and so on. The control also allows you to browse any attached files and open the Attachments dialog box. If you open the dialog box from a form, you can add, remove, edit, and save attachments. If you open the dialog box from a report, you can only save attachments to your hard disk drive or a network location, because reports are read-only by design.

The steps in the following sections explain how to add an image control to a form or report, and how to scroll through records, attach files, and view your attachments. Remember that you can scroll through attachments only when a given record contains more than one attachment.

Add the attachment control to a form or report

The steps in this section explain how to add the attachment control to a form or report, and then bind the control to an Attachment field in an underlying table. You follow the same steps when adding the attachment control to a form or a report. Before you start, remember that at least one of the tables in your database must have an attachment field. For information on adding an attachment field, see Add an attachment field to a table earlier in this article.

 Note   Because form and report design can be complex processes, the steps in these sections assume that you already have a database with at least one table and one form or report. For information on creating tables, forms, or reports, see the following articles:

Add the attachment control

  1. In the Navigation Pane, right-click the form or report that you want to change and click Design View on the shortcut menu.
  2. On the Design tab, in the Tools group, click Add Existing Fields.

The Field List pane appears and lists the fields in the table that provide the data for the form or report. The list denotes an attachment field by making it expandable (that is, you can click the plus or minus sign next to the field).

The following figure shows a typical attachment field in the Field List pane.

An Attachment field in the Field List task pane

  1. Drag the entire attachment field from the list to your form — the parent and child items — and drop it in the location that you want on your form.

Access places an attachment control on your form and binds the control to the table field for you.

  1. As needed, right-click the control and click Properties to display the property sheet for the control. Set or change the control properties to match the rest of your form or report.
  2. Save your changes, and then right-click the document tab and click either Form View or Report View to open the form or report for viewing.

If the underlying field contains image files, the control renders those files. If the field contains another type of file, such as a Word document or PowerPoint presentation, the control displays the appropriate icon for that file type.

Manage attachments by using a form

After you add an attachment control to a form, you can add, edit, remove, and save attached files directly from that form. When a record contains multiple attachments, you can also scroll through the attached files, which you cannot do when working with a table.

 Note   The person who designed the form may have made the form read-only. If that is the case, you can use the Attachments dialog box only to save attached files to your hard disk drive or a location on your network.

Attach a file

  1. Open the form that displays your attachments, and locate the record to which you want to attach a file.
  2. Select the attachment control — the control that is bound to the Attachment field.

The Mini toolbar appears: The Attachment mini toolbar

 Note   If you added the attachment control to the datasheet section of a split form, the Mini toolbar does not appear. For more information about split forms, see the article Create a split form.

  1. Click the View Attachments button (the paperclip icon) to open the Attachments dialog box.
  2. In the dialog box, click Add.

The Choose File dialog box appears.

  1. Use the Look in list to navigate to the file that you want to attach, and then click Open.
  2. Repeat steps 4 and 5 as needed to attach more files.

Scroll through the attached files

 Note   The steps in this section apply to forms and reports.

  1. Open the form or report that displays your attachments.
  2. Navigate to the record that contains the attached files.
  3. Click the image control that displays the attached files.

The Mini toolbar appears.

  1. Click the Back (left) or Forward (right) arrows to scroll through the attached files. If you want to know the names of the files, click the View Attachments button to open the Attachments dialog box. The names of attached files appear in the Attachments list.

Top of Page Top of Page

Save attached files to other locations

The steps in this section apply to tables, forms, and reports. You can save either one or all of the files that are attached to a given record to locations on your hard disk drive or network. Remember that when you choose to save all files, you cannot choose to save some of the files — you must save them all. To selectively save files, you need to do so one at a time.

  • Open the table, form, or report that contains your attachments, and then open the Attachments dialog box.

ShowOpen the Attachments dialog box from a table

  • Open the table in Datasheet view, and then double-click the attachment field that contains the attachment you want to save.

ShowOpen the Attachments dialog box from a form or report

  1. Open the form or report that displays your attachments.
  2. Navigate to the record that contains the attached files.
  3. Click the image control that displays the attached files.

The Mini toolbar appears.

  1. Click the View Attachment button.

Save a single attachment

  1. In the Attachments dialog box, click Save As.

The Save Attachment dialog box appears.

  1. Use the Save in list to navigate to the new location for your file, and then click Save.

Save all attachments

  1. In the Attachments dialog box, click Save All.

The Save Attachments dialog box appears.

  1. Use the Look in list to navigate to the new location for your files, and then click Save.

Top of Page Top of Page

Remove attached files

The steps in this section apply to tables and forms.

Remove an attachment

  1. Double-click the attachment field in your table to open the Attachments dialog box.

–or–

In your form (in either Layout view or Form view), navigate to the record that contains the attachment you want to remove, and click the View Attachment button on the Mini toolbar to open the dialog box.

  1. In the Attachments dialog box, select the file that you want to delete and click Remove.

Top of Page Top of Page

Use attachments without a mouse or other pointing device

The following section explains how to use your keyboard to place focus in the Navigation Pane and open the table, form, or report that contains attached files. The steps also explain how to browse attached files and open the Attachments dialog box.

Open a table, form, or report from the Navigation Pane

  1. Press F11.

 Note   If the Navigation Pane is closed, pressing F11 opens it and places the focus in the pane. If the pane is open, pressing F11 closes it. You must press F11 again to open the pane and shift focus to it.

  1. Use the UP ARROW and DOWN ARROW keys to select the table, form, or report that you want to open.
  2. Press ENTER to open the selected object.

If you open a table, Access places the cursor in the first field in the table. If you open a form or report, Access places the focus in the first field.

View attachments from tables

  1. As needed, use the arrow keys to move the cursor to the attachment field that you want.
  2. Press the SPACEBAR.

The Attachments dialog box appears.

  1. Press the TAB key to move among the buttons in the dialog box and to move from the buttons to the list of attached files under Attachments.

 Note   Records may contain more than one attachment. If you need to select an attachment from a list of two or more files, press the TAB key to move to the file list, and then use the arrow keys to select the file that you want. Next, press the TAB key to return to the buttons and select the action that you want.

  1. When you select the file and button that you want, press ENTER.
  2. When you finish, press the key TAB, or use the UP ARROW and DOWN ARROW keys to select OK, and then press ENTER.

Scroll through attachments from a form or report

 Note   These steps apply only if you have a Microsoft Natural Keyboard and when a record contains more than one attachment.

  1. As needed, press the TAB key to move the focus to the attachment control. By default, Access highlights the control and the label associated with the control, if the label exists.
  2. Press the Application key.

A shortcut menu appears.

  1. Press the TAB key, or use the arrow keys to select either Forward or Back, and then press ENTER.
  2. Repeat step 2 as needed to scroll among the attached files.

Open the Attachments dialog box from a form or report

 Note   These steps apply only if you have a Microsoft Natural Keyboard.

  1. As needed, press the TAB key to move the focus to the attachment control. By default, Access highlights the control and the label associated with the control, if the label exists.
  2. Press the Application key.

A shortcut menu appears.

  1. Press the TAB key, or use the arrow keys to select View Attachments, and then press ENTER.

The Attachments dialog box appears.

  1. Press the TAB key to move among the buttons in the dialog box and to move from the buttons to the list of attached files under Attachments (Double-click to edit).

 Note   Records may contain more than one attachment. If you need to select an attachment from a list of two or more files, press the TAB key to move to the file list, and then use the arrow keys to select the file that you want. Next, press the TAB key to return to the buttons and select the action that you want.

  1. When you select the file and button that you want, press ENTER.
  2. When you finish, press the TAB key or use the arrow keys to select OK, and then press ENTER.

Top of Page Top of Page

Attachments reference

The following sections provide reference information about attachments, including the image and document file formats that attachments support, file-naming conventions, and some information about attaching files to records programmatically.

Supported image file formats

Office Access 2007 supports the following graphic file formats natively, meaning the attachment control renders them without the need for additional software.

BMP (Windows Bitmap)

RLE (Run Length Encoded Bitmap)

DIB (Device Independent Bitmap)

GIF (Graphics Interchange Format)

JPEG, JPG, JPE (Joint Photographic Experts Group)

EXIF (Exchangeable File Format)

PNG (Portable Network Graphics)

TIFF, TIF (Tagged Image File Format)

ICON, ICO (Icon)

WMF (Windows Metafile)

EMF (Enhanced Metafile)

Supported formats for documents and other files

As a rule, you can attach any file that was created with one of the 2007 Microsoft Office system programs. You can also attach log files (.log), text files (.text, .txt), and compressed .zip files.

File-naming conventions

The names of your attached files can contain any Unicode character supported by the NTFS file system used in Microsoft Windows NT (NTFS). In addition, file names must conform to these guidelines:

  • Names must not exceed 255 characters, including the file name extensions.
  • Names cannot contain the following characters: question marks (?), quotation marks ("), forward or backward slashes (/ \), opening or closing brackets (< >), asterisks (*), vertical bars or pipes (|), colons (:), or paragraph marks (¶).

Types of files that Access compresses

When you attach any of the following file types to a database, Access compresses them if they are not already compressed natively.

File Extension Compressed? Reason
.jpg, .jpeg No Already compressed
.gif No Already compressed
.png No Already compressed
.tif, .tiff Yes  
.exif Yes  
.bmp Yes  
.emf Yes  
.wmf Yes  
.ico Yes  
.zip No Already compressed
.cab No Already compressed
.docx No Already compressed (Metro file)
.xlsx No Already compressed (Metro file)
.xlsb No Already compressed (Metro file)
.pptx No Already compressed (Metro file)

Blocked file formats

Office Access 2007 blocks the following types of attached files. At this time, you cannot unblock any of the file types listed here.

.ade .ins .mda .scr
.adp .isp .mdb .sct
.app .its .mde .shb
.asp .js .mdt .shs
.bas .jse .mdw .tmp
.bat .ksh .mdz .url
.cer .lnk .msc .vb
.chm .mad .msi .vbe
.cmd .maf .msp .vbs
.com .mag .mst .vsmacros
.cpl .mam .ops .vss
.crt .maq .pcd .vst
.csh .mar .pif .vsw
.exe .mas .prf .ws
.fxp .mat .prg .wsc
.hlp .mau .pst .wsf
.hta .mav .reg .wsh
.inf .maw .scf

Attach files to records programmatically

Office Access 2007 exposes an object model and programming interfaces for attaching files to records programmatically by using Visual Basic for Applications (VBA) code. For information about attaching files programmatically, see the articles "LoadFromFile" and "SaveToFile," on the Microsoft Developer Network — http://msdn.microsoft.com.

Top of Page Top of Page

 
 
Applies to:
Access 2007