Thursday, November 21, 2013

Storing PDFs in MS Access

Store is as a binary:http://stackoverflow.com/questions/858915/storing-pdfs-in-ms-access-database-using-forms

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
This text is after the block

Microsoft website solution is quite long: http://support.microsoft.com/kb/103257


Amara BLOB example:

http://www.ammara.com/access_image_faq/read_write_blob.html


'Read the file 'Image-In.jpg' into the field named 'Image'.
FileToBlob "C:\Photos\Image-In.jpg", [Image]

'Extract the file contained in the field named 'Image' to a file named 'Image-Out.jpg'.
BlobToFile "C:\Photos\Image-Out.jpg", [Image]




'Function:  BlobToFile - Extracts the data in a binary field to a disk file.
'Parameter: strFile - Full path and filename of the destination file.
'Parameter: Field - The field containing the blob.
'Return:    The length of the data extracted.
Public Function BlobToFile(strFile As StringByRef Field As ObjectAs Long
    On Error GoTo BlobToFileError

    Dim nFileNum As Integer
    Dim abytData() As Byte
    BlobToFile = 0
    nFileNum = FreeFile
    Open strFile For Binary Access Write As nFileNum
    abytData = Field
    Put #nFileNum, , abytData
    BlobToFile = LOF(nFileNum)

BlobToFileExit:
    If nFileNum > 0 Then Close nFileNum
    Exit Function

BlobToFileError:
    MsgBox "Error " & err.Number & ": " & err.Description, vbCritical, _
           "Error writing file in BlobToFile"
    BlobToFile = 0
    Resume BlobToFileExit

End Function


'Function:  FileToBlob - Loads a file into a binary field.
'Parameter: strFile - Full path and filename of the source file.
'Parameter: Field - The binary field into which the file is to be loaded.
Public Function FileToBlob(strFile As StringByRef Field As Object)
    On Error GoTo FileToBlobError

    If Len(Dir(strFile)) > 0 Then
        Dim nFileNum As Integer
        Dim byteData() As Byte

        nFileNum = FreeFile()
        Open strFile For Binary Access Read As nFileNum
        If LOF(nFileNum) > 0 Then
            ReDim byteData(1 To LOF(nFileNum))
            Get #nFileNum, , byteData
            Field = byteData
        End If
    Else
        MsgBox "Error: File not found", vbCritical, _
               "Error reading file in FileToBlob"
    End If

FileToBlobExit:
    If nFileNum > 0 Then Close nFileNum
    Exit Function

FileToBlobError:
    MsgBox "Error " & err.Number & ": " & err.Description, vbCritical, _
           "Error reading file in FileToBlob"
    Resume FileToBlobExit

End Function


Display BLOB images in MS Access Report
http://bytes.com/topic/access/answers/909583-how-display-blob-images-ms-access-report


http://bytes.com/topic/access/answers/564980-image-blobs-please-help

ADO stream object - this may only work with SQL
http://support.microsoft.com/kb/258038

CodeProject
http://www.codeproject.com/Articles/16851/Uploading-and-Downloading-BLOBs-to-Microsoft-Acces

No comments:

Post a Comment