Microsoft KB Archive/158941

= ACC: How to Load OLE Objects from a Folder into a Table =

Article ID: 158941

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q158941



Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
This article shows you how to automatically append all files with a particular extension from a specified folder on the hard disk into 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.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

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.

For information about working programmatically with an OLE object in a form in Microsoft Access version 2.0, please see the following article in the Microsoft Knowledge Base:

114214 ACC2: How to Programmatically Embed or Link an Object in a Form



Method to Import OLE Object Files
  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  Using the AutoForm: Columnar Wizard, create a new form based on the tblLoadOLE table. Save it as frmLoadOLE. Open the frmLoadOLE form in Design view.  Create 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   Create a command button on the form: <pre class="fixed_text">      Command Button --      Name: cmdLoadOLE Caption: Load Files </li>  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. ' For Access 95 only, use the following Line of code: DoCmd.DoMenuItem acFormBar, acEditMenu, 12, 4, acMenuVer70

' For Access 97 only, use the following line of code: 'DoCmd.RunCommand acCmdRecordsGoToNew Loop

End Sub </li> Save the frmLoadOLE form and open it in Form view.</li> Type the full path name of the folder you want to search in the SearchFolder text box.</li> Type the file extension you want to load in the SearchExtension text box, such as bmp, jpg, doc, xls, tif, or gif. Do not type a period as part of the extension.</li> Type the Class name for the type of file 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.</li> Click the Load Files button. Note that All files that match the SearchFolder and SearchExtension you entered are added to the tblLoadOLE table.</li></ol>

Additional query words: Directory Multiple pictures images picture image

Keywords: kbhowto kbinterop kbprogramming KB158941

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.