Storing PDFs in MS Access Database Using Forms - Stack Overflow
Storing PDFs in MS Access Database Using Forms - Stack Overflow
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
2 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.
ms-access
Share Improve this question Follow edited May 14, 2009 at 15:08 asked May 13, 2009 at 16:18
Matthew Jones
26k 17 104 156
Are you absolutely certain you want to store the PDFs in OLE fields? You don't say what version of Access, but pre-
2007, there was huge overhead for this. Unless there's some unmentioned requirement, it's better to store the files in
the file system and just put the path/filename in a text field in your data table. – David-W-Fenton May 13, 2009 at
22:39
This database will be accessible from a share drive. So, as I understand it, the filesystem will look different (based
upon the drive the user has mapped our share to). This is why we were not using linking. If we can avoid this
limitation, obviously I would want to use linking instead of storing the file outright. – Matthew Jones May 14, 2009
at 14:02
1 This is an old thread, but I never say Matthew's response to my question. To it, I'd say: don't use mapped drives, but
use UNC paths, which will always be the same unless the server name changes or the share mapping changes. If
either of those things happened, drive mappings would be invalidated, anyway. – David-W-Fenton Mar 12, 2010 at
4:17
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:
4
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.
Share Improve this answer Follow answered May 14, 2009 at 11:42
https://stackoverflow.com/questions/858915/storing-pdfs-in-ms-access-database-using-forms 1/3
7/14/24, 7:30 PM Storing PDFs in MS Access Database using Forms - Stack Overflow
Birger
4,343 22 35
@birger Thanks 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 May 14, 2009 at 15:15
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 May 14, 2009 at 15:20
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 May 14, 2009 at 15:22
+1, very interesting. I suppose that doing that way you avoid a LOT of size and processing overhead, but lose some
functionality (like preview in a form or in place edit) – iDevlop Mar 13, 2013 at 14:56
The OLE overhead is not much. But in place edit is really broken in Access 2010 so I'm glad we don't use that
anymore! – Birger Mar 14, 2013 at 8:15
If you used the same concept but upsized to SQL Server- storing PDFs inside of an Image datatype (or
varbinary(max)) then you could SEARCH INSIDE THE PDFs using Full Text Search.
2
I show that Microsoft says you can do this for any file type where you can register an IFILTER product.. and
I just was at the Adobe website the other day and say that their Acrobat IFILTER is indeed FREE.
Share Improve this answer Follow answered Jan 16, 2011 at 17:35
Aaron Kempf
588 2 11
Very interesting ! But I guess this would only work with objects stored as OLE, not as blob like @birger's answer ?
– iDevlop Mar 13, 2013 at 14:54
ole in Access is the same as blobs in SQL Server.. blobs are basically the same whether it's a IMAGE datatype or
varbinary(max), etc – Aaron Kempf Mar 14, 2013 at 0:12
Thanks. Agreed for the storage, but when you store "as OLE", you put the doc (or even a part of a doc) in a kind of
enveloppe, including information on the possible client(s), a format description, a preview, etc... So I was wondering if
that OLE enveloppe is required for iFilter to do its job ? – iDevlop Mar 14, 2013 at 9:01
1 I don't think so. I've definitely pushed DOC/DOCX into VarBinary(max) datatypes, and then I'm able to do FullText
Search for keywords stored in the document, and it works like a charm. I frequently use a product called Access Data
Projects in order to populate SQL Server with blobs. Literally create a new form bound to a single SQL Server table,
and this will automatically use the OleObject ActiveX control type which allows you to double-click on a
WordDocument stored in SQL Server in order to launch words. – Aaron Kempf Mar 14, 2013 at 16:38
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.
0
Share Improve this answer Follow answered May 13, 2009 at 16:31
Ralph M. Rickenbach
13k 5 30 49
https://stackoverflow.com/questions/858915/storing-pdfs-in-ms-access-database-using-forms 2/3
7/14/24, 7:30 PM Storing PDFs in MS Access Database using Forms - Stack Overflow
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 May 13, 2009 at 17:29
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
0 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.
Share Improve this answer Follow answered May 14, 2009 at 4:08
JeffO
8,025 3 45 54
https://stackoverflow.com/questions/858915/storing-pdfs-in-ms-access-database-using-forms 3/3