ACC2000: How to Load OLE Objects from a Folder into a Table
ID: Q198466
|
The information in this article applies to:
SUMMARY
Moderate: Requires basic macro, coding, and interoperability skills.
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, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals 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 needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the
following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
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
- Use the AutoForm: Columnar Wizard to create a new form based on the
tblLoadOLE table. Save it as frmLoadOLE.
- Open the frmLoadOLE form in Design view.
- 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
- Create the following 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.RunCommand acCmdRecordsGoToNew
Loop
End Sub
- Save the frmLoadOLE form and open it in Form view.
- In the SearchFolder text box, type the full path name of the folder
that you want to search.
- 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.
- 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.
- Click the Load Files button. Note that All files that match the
SearchFolder and SearchExtension that you entered are added to the
tblLoadOLE table.
Additional query words:
Directory Multiple
Keywords : kbdta AccCon IntpOle KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto