Storing PDFs in MS Access Database using Forms - ms-access

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.

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.

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.
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.

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.

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.

Related

AS3 Sending a Shared Object

I'm working on an application that would allow users to create a custom character sheet for role play games. I have most of the code figured out, but I want users to be able to send their character sheets between devices.
So here's the question: is there a way to save and send a shared object file, or a way to create a txt file that can easily be saved and copied?
I don't believe you can send a SharedObject from one device to another, at least without a lot of work. You could however create an XML file containing the data and save that up to a server. You could allow the user to then download character sheets from your server and the app would read the XML data before converting to a SharedObject. Can't really provide any code for this as the details are lacking.
If I understand you correctly, you could sort of do this.
You cannot literally "send and receive" a SharedObject (well, you might be able to copy your shared object data on the file system directly, but not from Flash).
What you can do is provide options to the user to save and load a file that encodes all the shared data in AMF bytes. Here's the general idea:
First you need to give the user an option to save their data. You can use ByteArray/writeObject() to write your data using the same AMF format that SharedObjectuses, and FileReference/save() to allow the user to save it to a file on their file-system.
Next, you can use FileReference/load() to load the file and ByteArray/readObject() to read all the data into AS3. Now you can simply store it in the SharedObject however you want, just like you did before.

How to attach documents in ms access using vb6

Good day. I have an Access database with a field using an attachment data type. Is there a way to use Visual Basic 6 to attach my documents, such as images, Word files and PDF files on that database? Specifically on the field using the attachment data type.
Yes, from the LoadFromFile Method.
Snippet below:
Set AttachmentRecordset = RecordSetForTable.Fields("AttachmentFieldName").Value
FileName = "SomePathToAFile"
AttachmentRecordset.AddNew
AttachmentRecordset.Fields("FileData").LoadFromFile (FileName)
AttachmentRecordset.Update

Creating a Document Database using Microsoft Access

I am attempting to create a table within a database which store all of the documents related to the database "in it". What I really want to do is have a file uploaded and have vba code which copies the file to a network location, renames the file by concatenating two fields from the document table form (eliminating the issue of duplicate file names in the external location), and then stores the file name and file path in a file path field in the table. I am very new to access and vba so I am having difficulty getting everything to work. The code I currently have is below:
Option Compare Database
Private Sub Command15_Click()
Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = False
If f.Show Then
For i = 1 To f.SelectedItems.Count
sFile = Filename(f.SelectedItems(i), sPath)
MsgBox sPath & "---" & sFile
Next
End If
End Sub
Public Function Filename(ByVal strPath As String, sPath) As String
sPath = Left(strPath, InStrRev(strPath, "\"))
Filename = Mid(strPath, InStrRev(strPath, "\") + 1)
End Function
I can not seem to get a handle on how to move, rename by concatenating the two fields from the form, or store the path in the path field of the table. I have been to the following locations to obtain what information I could
ms access browse for file and get file name and path
VBA to copy a file from one directory to another
I am currently using Microsoft Access 2010, and I do not wish to use the file attachment field type because of database size constraints. Currently I press a button and a file explorer appears to navigate to the file being uploaded, and the path and file name are entered into strings. After this point I am lost. If any other information is needed please let me know. Thanks in advance for the assistance.
I believe your approach to managing the documents is right. In most cases, it doesn't make much sense to store documents in the database itself when the filesystem is a more suited to this job.
What you are doing is fairly straightforward but the main complexity will come from the correct management of the various paths and filenames and extracting the right information from them.
It can become tricky if you're not using some helper functions to to dissect and recompose the various bits of the paths.
I have created a sample database that has a few functions. Might not be exactly in line with what you need but you can easily play around with it to suit your particular case.
The sample database includes a Tools VBA module that has a few useful functions to split a Path into its constituents.
Basically, the database has 2 forms.
The main form allows you to set the network path where the files are to be saved.
You can then select a pre-defined Account number (listed in the Account table) associated with a document, then click the upload button.
This creates a new record in the Document table and opens a form where you can edit the document title and click a button to upload a file to the server.
The file selected by the user is copied to the server after its path has been transformed.
I took the assumption that the file would keep its original extension, the filename would be renamed to the ID of the Document record where the file information is saved (like 5845.pdf) and that the folder where the file is saved on the server would be the account number, so that a source file selected by the user
C:\Users\user\Desktop\SuperSecretFile.pdf
would be saved as, for instance:
\\docserver\files\123-55547\5845.pdf
The Main form also allows you to update an existing record, open the file from the server, open the server's folder where the file is located or even copy the server file back to the user's computer with the original name of the file.
I'll let you play around with it. Let me know if you have any issues.

The difference between using an OLE Object and an Attachment in Access 2007?

I'm learning Access 2007, and among the list of data types are the OLE Object and the Attachment.
The text has this to say about Attachments:
You can use attachments to store
several files, and even different
types of files, in a single field. The
Attachment field is new for Access
2007 and stores data files more
efficiently than using other fields
like the OLE Object field.
More efficiently than OLE Objects?
What is the purpose and proper use of the Attachment data type? And how is it related to the OLE Object?
WHY THE OLE OBJECT IS A BETTER SOLUTION THAN THE ACCESS ATTACHMENT DATA TYPE
The default user interface for the OLE Object storage system is clumsy. The attachment data field introduced in Access 2007 has an improved user interface making it easier to work with different file types. Unfortunately, beginning in Access 2013 and continuing in Access 2016, Microsoft developed a fatal glitch that they have not addressed with a Windows update. If you have saved a Microsoft Word document in an Access Attachment field, you can edit the Word Document, but it cannot be saved in Access. When you click 'Save' you are prompted to save the document to a file. It won't save to the Access database. Other file types will save to the database such as Excel spreadsheets.
Because of this Microsoft glitch, I was forced to develop an improved user interface for the OLE Object data field. In a nutshell, it is a one to many relationship table that saves the file name and file in an OLE Object data field. The user interface opens file explorer to add the file. I use ShellExucute to open the document via Windows which has much more flexibility to file types than the Access default user interface.
The Access Attachment data type is limited to Microsoft Access databases. The OLE Object data type can be migrated to an SQL Server database where the content within the stored documents can be searched with an SQL Server query. A lot of power there! Just my opinion.
Not an exhaustive answer, but I recently tried to use an OLE object field to store images to be printed through a report.
To make the story short, it does not work very easily, and is restricted to 2 little used image formats.
Using an Attachment field, it works like a charm and you can use .PNG files as well.
Note 1: Attachment is NOT available in .MDB so I had to migrate to ACCDB.
Note 2: OLE Object field can be migrated to SQL Server, Attachment field cannot
Judging from this description, I would say that it is some sort of native binary field.
OLE Object fields were really just containers for OLE objects. They suffered from considerable bloat, and were clumsy to use.

Extract OLE object containg images using VBscript

An OLE Object column contains images but the image type (jpg/gif/tiff) is unknown. These images need to be extracted from the DB and saved to disk using VBscirpt.
I've done this before in Delphi, the solution was to use the clipboard (somehow the clipboard can determine the type of image). Copy the contents of the field to the clipboard and then save the contents of the clipboard to a file.
OLE objects is bad way of storing images in MS Access. Use OLEToDisk to save your images as pic files.
After that reimport them in nice way. Check AccessImagine for working with images in Access - it does all the hard job.
Here I found an example to take a screenshot with VBScript and paste it to MS Paint. Maybe you can modify it to do what you want?
http://hisudhakar.spaces.live.com/blog/cns!8DDF980C45482279!410.entry?sa=948299040