tags:

views:

1895

answers:

3

I need to store PDF files in an Access database on a shared drive using a form. I figured out how to do this in tables (using the OLE Object field, then just drag-and-drop) but I would like to do this on a Form that has a Save button. Clicking the save button would store the file (not just a link) in the database. Any ideas on how to do this?

EDIT: I am using Access 2003, and the DB will be stored on a share drive, so I'm not sure linking to the files will solve the problem.

A: 

Maybe this will help: ACC2000: Reading, Storing, and Writing Binary Large Objects (BLOBs).

What they do: Read a file in chunks and add it to a blob using a VBA function.

Ralph Rickenbach
I am really new (< 1 week) to Access and VBA, so this seems awful complicated to me. I think it does what I want, but is there anything simpler out there?
Matthew Jones
A: 

A field of OLE Object, by default would use a Bound Object Frame on the form. Right click on it and you can Insert an object. It comes complete with browsing for the file. Double-click on the field and the actual document will open.

I recommend going with David's advice and link. Unless you have a need to transfer a single file and want all the PDF's included. Size and performance will be an issue.

If security is an issue and the Access file is the only control you have (You are unable to set security on the folder containing all the linked files.), then you would have to embed.

Jeff O
A: 

We have several databases that contain 10's of thousands of documents (pdf, doc, jpg, ...), no problem at all. In Access, we use the following code to upload a binary object to a binary field:

Function LoadFileFromDisk(Bestand, Optional FileName As String = "")
  Dim imgByte() As Byte
  If FileName = "" Then FileName = strFileName
  Open FileName For Binary Lock Read As #1
  ReDim imgByte(1 To LOF(1))
  Get #1, , imgByte
  Close #1
  If Not IsEmpty(imgByte) Then Bestand.Value = imgByte
End Function

In this case, Bestand is the field that contains the binary data. We use MS SQL Server as a backend, but the same should work on an Access backend.

birger
@birgerThanks for the suggestion. I tried implementing this code, but being so new to VBA I cannot for the life of me figure out how to implement it. Could you explain, for example, what the "#1" and LOF names mean?
Matthew Jones
A file is opened, and it is assigned a number (#1). imgByte is an array of bytes. The size of this array is set to the length of the file 1: LOF(1).The GET function reads the file, and stores it into imgByte. At that point, imgByte is an array of bytes representing the image file.The Bestand field value is then set to this array and voila: the file is stored in the field.
birger
End please note: this is something else than storing an object in an OLE field, because theis method does not add the OLE wrappings to the file.
birger