PDA

View Full Version : Sleeper: Importing PDF files into MS Access as OLE Embedded Objects Via VBA Form Load



cnc4496
01-17-2010, 10:35 PM
I have been trying to do this for several days now and have exhausted the options that I have previously found posted. I have a need to be able to loop through a file directory and import each .pdf into an Access table as an embedded OLE object. I cannot link these in, they must be embedded. The number of pdf files is relatively minimal (50-60) but this will be used multiple times for several different Access databases. What I have tried this far is to import them via a form load, but it keeps getting hung up on [OLEFile].Action = acOLECreateEmbed saying that it is an invalid action. Here is my code, any assistance would be much appreciated:



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
MyPath = MyFolder & "\" & "*." & [SearchExtension]
MyFile = Dir(MyPath, vbNormal)
Do While Len(MyFile) <> 0
[OLEPath] = MyFolder & "\" & MyFile
[OLEFile].Class = "Adobe Acrobat Document"
[OLEFile].OLETypeAllowed = acOLEEmbedded
[OLEFile].SourceDoc = [OLEPath]
[OLEFile].Action = acOLECreateEmbed
DoCmd.RunCommand acCmdRecordsGoToNew
MyFile = Dir
Loop
End Sub

OBP
01-20-2010, 04:42 AM
Why is it necessary to Imbed the objects, rather than just refering to them via their full Paths?

cnc4496
01-20-2010, 07:13 AM
The user must access the pdf files via Access while not connected to the network. The files can't be saved to a non-network location so it must be embedded. It doesn't have to be accomplished via a form load, I'm open to suggestions as to other ways to do this.

OBP
01-20-2010, 09:18 AM
This is what I use


Me.test.Class = "Package" ' Set class name.
' Specify type of object.
Me.test.OLETypeAllowed = acOLEEmbedded
' Specify source file.
Me.test.SourceDoc = Me.Document_Location
' Create linked object.
Me.test.Action = acOLECreateEmbed
' Adjust control size.
Me.test.SizeMode = acOLESizeZoom
With Me.test
.Action = acOLEActivate
.Verb = acOLEVerbOpen
End With

stanl
01-24-2010, 09:35 AM
This is what I use


I stand to be corrected, but I have always thought the main problem with linking pdf or image data into access has been portability and have therefore always used an ADO Stream to embed the files directly into an Access BinaryOLE field. This permits users to query or create a disconnected recordset - place it on a laptop and pull up the binary data from say a customer site. .02 Stan