Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Load OLE Objects from a Folder into a Table

View products that this article applies to.

This article was previously published under Q198466
Moderate: Requires basic macro, coding, and interoperability skills.

↑ Back to the top


This article shows you how to automatically append all files with a particular extension from a specified folder on the hard disk to a table. This routine is good for loading OLE objects, such as .gif, .jpg, .doc, .xls, or .bmp files that are associated with an OLE Server, into a Microsoft Access database.

NOTE: To associate a graphic file with an OLE Server, open it with an OLE Server package, such as Microsoft Imager or Microsoft Paint, and save the file.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

↑ Back to the top

More information

Method to Import OLE Object Files

  1. Create the following new table in Design view. Save it as tblLoadOLE:
       Table: tblLoadOLE
       Field Name: OLEID
          Data Type: AutoNumber
       Field Name: OLEPath
          Data Type: Text
          Field Size: 255
       Field Name: OLEFile
          Data Type: OLE Object
       Table Properties: tblLoadOLE
       PrimaryKey: OLEID
  2. Use the AutoForm: Columnar Wizard to create a new form based on the tblLoadOLE table. Save it as frmLoadOLE.
  3. Open the frmLoadOLE form in Design view.
  4. Create the following three unbound text box controls in the form header section of the form:
       Form: frmLoadOLE
       Text Box:
          Name: SearchFolder
       Text Box:
          Name: SearchExtension
       Text Box:
          Name: OLEClass
  5. Create the following command button on the form:
       Command Button
       Name: cmdLoadOLE
       Caption: Load Files
  6. Type the following event procedure in the OnClick property of the cmdLoadOLE button:
    Private Sub cmdLoadOLE_Click()
       Dim MyFolder As String
       Dim MyExt As String
       Dim MyPath As String
       Dim MyFile As String
       Dim strCriteria As String
       MyFolder = Me!SearchFolder
       ' Get the search path.
       MyPath = MyFolder & "\" & "*." & [SearchExtension]
       ' Get the first file in the path containing the file extension.
       MyFile = Dir(MyPath, vbNormal)
       Do While Len(MyFile) <> 0
          [OLEPath] = MyFolder & "\" & MyFile
          [OLEFile].Class = [OLEClass]
          [OLEFile].OLETypeAllowed = acOLEEmbedded
          [OLEFile].SourceDoc = [OLEPath]
          [OLEFile].Action = acOLECreateEmbed
          ' Check for next OLE file in the folder.
          MyFile = Dir
          ' Go to new record on form.
          DoCmd.RunCommand acCmdRecordsGoToNew
    End Sub
  7. Save the frmLoadOLE form and open it in Form view.
  8. In the SearchFolder text box, type the full path name of the folder that you want to search.
  9. In the SearchExtension text box, type the file extension that you want to load, such as bmp, jpg, doc, xls, tif, or gif. Do not type a period as part of the extension. For example, do not type .bmp.
  10. Type the Class name for the type of file that you are loading, such as Paint.Picture for .bmp files.

    NOTE: To determine the Class name of an OLE object, see the documentation for the application supplying the object.
  11. Click the Load Files button. Note that All files that match the SearchFolder and SearchExtension that you entered are added to the tblLoadOLE table.

↑ Back to the top

Keywords: KB198466, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 198466
Revision : 5
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 372