The information in this article applies to:
- Microsoft Access versions 7.0, 97
SUMMARY
Moderate: Requires basic macro, coding, and interoperability skills.
This article describes a method 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:
ARTICLE-ID: Q114214
TITLE : ACC2: How to Programmatically Embed or Link an Object in a
Form
MORE INFORMATION
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:
Command Button
--------------
Name: cmdLoadOLE
Caption: Load Files
- 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 = 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.DoMenuItem acFormBar, acEditMenu, 12, 4, acMenuVer70
Loop
End Sub
- Save the frmLoadOLE form and open it in Form view.
- Type the full path name of the folder you want to search in the
SearchFolder text box.
- 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.
- 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.
- Click the Load Files button. Note that All files that match the
SearchFolder and SearchExtension you entered are added to the
tblLoadOLE table.