+ Reply to Thread
Results 1 to 2 of 2

Store Bitmap Object In Excel 2003 To Access Database?

  1. #1
    Registered User
    Join Date
    08-03-2008
    Location
    76018
    Posts
    1

    Store Bitmap Object In Excel 2003 To Access Database?

    Hi all,

    I have a worksheet that I've inserted a Bitmap object on. (I clicked Insert, Object, Bitmap Object). I renamed it from 'Object 1' to 'Signal'. After drawing on the bitmap object, I want to write some VBA code to store the bitmap image to an Access 2003 database. I know how to store text and numbers already, but how would I do it with a bitmap object? I know Access has OLEObject fields... is that something to look into? I just don't know what code to use to achieve this, or how to select the object in Excel with VBA code. I've scoured the 'net and can't find anything. Any help is much appreciated!

    Thanks

  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    This is directly from the help files:
    Quote Originally Posted by MS Help files
    Store images in a database
    Show All
    Hide All
    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.



    --------------------------------------------------------------------------------

    About storing images in an Access database
    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?

    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 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.

    Add an OLE Object field to an existing table

    Open the table in Design view .
    In the first blank row of the design tool, under Field Name, enter Image.
    Click the next field (the field in the Data Type column), and select OLE Object from 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)," later in this section.
    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, enter ID.
    Click the first field under Data Type and select AutoNumber from the list.
    Right-click anywhere in the first row and click Primary Key. This sets the ID field as the primary key for the table.
    In the next row, enter 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, and then open it in Datasheet view (double-click the table to reopen it).
    Continue to the next set of steps, "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. Alternatively, you can use your own tables and image files.

    Right-click the first field in the Image column of the table and click Insert Object.
    Click Create from File, and then click Browse.
    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.

    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.

    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.

    Open the table to which you want to add the field in Design view .
    In the first blank row of the design tool, under Field Name, enter Image.
    Click the next field (the field in the Data Type column), and select Text from 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



    Caution 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.
    Not all forums are the same - seek and you shall find

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1