Working with Shared Resources

Access 2010 includes a new feature called Shared Resources, which allows you to easily share images across multiple forms and reports. In previous versions of Access, when you wanted to display an image on a form or report, you embedded the image into the form or report design. In this case, Access saved the actual image with the form or report definition. You could also link to a graphic file stored on your computer or within a table to display on a form or report. Both of these methods of using images in your applications have drawbacks. When you wanted to reuse an image on multiple forms and reports, perhaps as a form or report background, you had to embed the image individually on each object. When you used this technique, however, your database size could increase dramatically because Access needed to save a copy of that image with each object. If you wanted to change the image used on all the objects, you had to manually delete each image and resave the new image into the object design. If you linked to images on your computer, the images would not show up in your objects if the file locations changed. Access developers also sometimes use subforms that display only a single image to reuse images across different objects; however, this technique does not work when you want to use an image on a command button or for a form or report background.

Shared Resources in Access 2010 helps you manage any images you use in your client or web databases by providing a simple way to share images across multiple forms and reports. When you use a shared image, Access stores the image file once in a system table. You can then reference that image on any form or report in your database without having to store multiple copies and unnecessarily increase the size of your database file.

You can use the Shared Resources feature in both client and web databases. In client forms and reports, you can easily convert existing embedded images into shared images. In web databases, all images used on web forms and web reports must be shared images; you cannot embed images into the web form or web report design as you can for client objects. For web forms and web reports displayed in a web browser, it makes sense to store an image once and reuse it in other places to decrease the amount of time it takes for web pages to load. The Shared Resources feature was built around this concept to make it easier for you to reuse images across forms and reports and increase the responsiveness of loading web forms and web reports in a web browser.

If you’ve closed the Contacts Map Copy sample web database, reopen the database and then open the Home form in Layout view. This web database includes several shared images used on the web forms and reports. Select the image control in the upper-left corner of the Home form and then click the Insert Image command on the far-right side of the Controls group on the Design tab to display the Image Gallery, as shown in Figure 14-73. Access displays all shared images in the current database in the Image Gallery.

Access displays all shared images in the Image Gallery.

Figure 14-73. Access displays all shared images in the Image Gallery.

The Image Gallery serves multiple purposes for managing your shared images. You can place a new shared image into an empty cell on a form or report, change an existing image control to use a different shared image, browse your computer for new images to add to your database, and rename, update, or delete existing shared images. Access enables the Insert Image button in the Controls group whenever you are on an empty cell or a control with a Picture property in the form or report grid. If you are on an empty cell and click an image in the Image Gallery, Access creates an image control in the empty cell and places the image into the image control.

As you can see in Figure 14-73, this web database includes four shared images. The image control on the Home form is currently using the shared image called imgContacts. Let’s change this image control’s properties to point to a different shared image. Click the shared image in the Image Gallery called imgEmployee. Access changes the image control and displays the imgEmployee shared image, as shown in Figure 14-74.

You can change an image control to use a different shared image by clicking a different shared image in the Image Gallery.

Figure 14-74. You can change an image control to use a different shared image by clicking a different shared image in the Image Gallery.

You can also change the shared image used by an image control through the Property Sheet window. Select the image control on the Home form and then click the Property Sheet button in the Tools group on the Design tab. On the Format or All tab, click the down arrow on the Picture property. Access displays a list of the four shared images stored in the database, as shown in Figure 14-75. When you click an image in the Image Gallery in Layout or Design view, Access changes this Picture property.

Click the Picture property to display a list of the shared images in the database.

Figure 14-75. Click the Picture property to display a list of the shared images in the database.

Inside Out: Converting Embedded or Linked Images to Shared Images

If you have embedded or linked images in your forms and reports from existing databases, you can easily convert them to shared images through the Property Sheet window. Open the form or report in Design view or Layout view, select the image control (or select the Form or Report if you are using an embedded or linked image for the background), and then open the Property Sheet window. Click the down arrow on the Picture Type property and then click Shared, as shown here:

Inside Out: Converting Embedded or Linked Images to Shared Images

Access converts the embedded or linked image into a new shared image. You can now view the shared image in the Image Gallery, rename the image if you want, and use the shared image on other forms and reports.

If you want to use a different image for a form or report that is currently not in the database, you can click the Browse button on the bottom of the Image Gallery, shown previously in Figure 14-74. When you click Browse, Access opens the Insert Picture dialog box, as shown in Figure 14-76. You can browse the folders on your computer for a new image to add to your database. Note that by default, Access limits the image files shown in the Insert Picture dialog box to files with extensions of .jpg, .jpeg, .jpe, .gif, and .png. To view additional file extensions, select All Files from the Web-Ready Image Files drop-down list.

You can browse for images to use in your database from the Insert Picture dialog box.

Figure 14-76. You can browse for images to use in your database from the Insert Picture dialog box.

When you select a new image to add to your database and click OK, Access inserts the new image into the system table, changes the Picture property of the selected control to use the new image, and adds the image to the Image Gallery. If you selected an empty cell on the form or report grid before clicking Browse, you can then add an image control to the grid. Access sets the Picture property to the name of the shared image and sets the Picture Type property to Shared for the image control. You can now use this new image for other controls on the current form or in other forms and reports. You can also browse for new images to add to your database by clicking the Builder button on the Picture property for a selected image. Access opens the Insert Picture dialog box from this entry point as well.

Inside Out: Convert All Embedded Images in Client Objects to Shared Images in Web Databases

If you are using a web database that includes client forms and reports, we recommend you change all embedded images on client forms and reports to shared images. When you publish a web database to a server running Microsoft SharePoint and Access Services, Access converts embedded images to text in client objects before sending to the server. Publishing and syncing client objects with embedded objects this way can significantly increase the publish and sync time because the image is converted to text. If you convert all embedded images in client objects to shared images in web databases, you’ll significantly decrease the amount of time it takes to publish and sync changes for your web database.

When you add images to your database, Access by default uses the file name to display in the Image gallery. You can rename the image through the Image Gallery after Access adds the new image into the database. Previously, you changed the image control on the Home form to use the imgEmployee shared image. Select that image control again, click the Insert Image button in the Controls group, and then right-click imgEmployee in the Image Gallery, as shown in Figure 14-77.

Right-click an image in the Image Gallery to rename it.

Figure 14-77. Right-click an image in the Image Gallery to rename it.

Access displays a shortcut menu of options for the selected shared image. If you click Delete, Access deletes the shared image from your database. Any image controls on any forms or reports that use that shared image will now display nothing because Access deleted the image. If you click Update on the shortcut menu, Access opens the Insert Picture dialog box so you can browse for a different image to use in place of the existing stored shared image. The update option is very useful, for example, when you want to replace an existing logo used on your forms and reports with an updated logo. If you click Rename on the shortcut menu, you can rename the stored shared image. (We’ll do that in just a moment.) Click the last option in the shortcut menu—Add Gallery To Quick Access Toolbar—to add the Image Gallery to the Quick Access Toolbar.

Caution

If you click Delete on the shortcut menu for the Image Gallery, as shown previously in Figure 14-77, Access does not prompt you for confirmation before deleting the image. Access permanently deletes the image from your database file, and there is no way to undo this action.

Inside Out: Using Shared Images as Backgrounds for Client Forms or Reports

You can use a shared image as the background for a client form or report. Click the Background Image button in the Background group on the Format tab and then select a shared image from the image gallery. You can also click Browse on the Image Gallery to browse for a new image to use for your form or report background.

Click Rename on the shortcut menu now so you can change the name of the shared image. Access opens the Rename Image dialog box, as shown in Figure 14-78. Access displays the existing the name of the shared image next to Old Name. Type imgNewEmployee in the New Name text box to change the name of this stored shared image, and then click OK to save your changes.

You can type a new name for shared images in the Rename Image dialog box.

Figure 14-78. You can type a new name for shared images in the Rename Image dialog box.

When you rename a shared image, Access only renames the shared image in the system table. Access does not change the Picture property for the selected control (or form and report if you are using a shared image for the background) to use the new name. If you save, close, and then reopen the Home form now, you’ll see nothing in the image control because Access still uses the old name of the shared image in the Picture property. If you rename a shared image, you’ll need to change the Picture property for each control on your forms and reports to use the new shared image name. You can either select the new name in the drop-down list of shared images on the Picture property, or select the control and then click the new shared image name in the Image Gallery to change the property.

Inside Out: Importing Shared Images

When you import a form or report into an Access 2010 database that utilizes shared images from a different database, Access also imports any shared images used by the form or report. If an existing shared image in the database performing the import has the same name as a shared image being imported, Access appends a number followed by an underscore to the start of the shared image name. For example, if you have an image called Employee in one database and import a form or report from another database that also has a shared image with that name, Access names the imported shared image as 1_Employee. The imported forms and reports will have their image controls referencing the Employee image in the destination database.

Now you should be comfortable with designing both basic client and web forms and adding special touches to make your forms more attractive and usable. In Chapter 15, you’ll learn advanced client and web form design techniques: using multiple-table queries in forms, building forms within forms, and working with Navigational Controls, Web Browser Controls, PivotTables, and PivotCharts.