show PDF image from pdf file stored as attachment on table (1 Viewer)

megatronixs

Registered User.
Local time
Today, 05:21
Joined
Aug 17, 2012
Messages
719
Hi all,

I have been trying to play with the attachments in the table.
in a table where there are some records, there a few attached pdf files. I can add it to the main form and it will show me this field that when I click on it, it will show the attachments, and then I can add, delete, view and so on. What I would like to get is something similar when you go to a website where they sell books. you will see all the books covers displayed on the form.
Is there a way to do such thing? I tried with the unbound object frame and then add them in the form (in view mode), I can them just drag those pdf from the folder inside and they will show up nicely, but when I close the form and open again, they are gone and the one that initially set there as per link, are back. The PDF files have to be on the database as it will be sent out per email and then the person there needs to have those attachment visible as they don't have access to the folders on our drive.
Maybe by linking the frames to the attachments in the table?

I have only this idea, but no clue what the possibilities are.

Greetings.
 

Ranman256

Well-known member
Local time
Yesterday, 23:21
Joined
Apr 9, 2015
Messages
4,337
I find it better to store the PATH to the pdf in the record. (path to the server)
1. it keeps the db file small. Storing the pdf in the db, enlarges it quickly.

2. It lets you open the pdf in its native PDF viewer. Opening pdfs inside access reports/forms gives a bad pixelated view.

paste this code into a module. (ctl-F11, insert , module)
Then it will open ANY file via its extension....
.pdf files will open in acrobat,
.doc files in word
etc

USAGE:
OpenNativeApp "c:\folder\file.xls"
'opens in excel
or
OpenNativeApp field
'opens item in field in native app

Code:
Option Compare Database
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Const SW_SHOWNORMAL = 1
Const SE_ERR_FNF = 2&
Const SE_ERR_PNF = 3&
Const SE_ERR_ACCESSDENIED = 5&
Const SE_ERR_OOM = 8&
Const SE_ERR_DLLNOTFOUND = 32&
Const SE_ERR_SHARE = 26&
Const SE_ERR_ASSOCINCOMPLETE = 27&
Const SE_ERR_DDETIMEOUT = 28&
Const SE_ERR_DDEFAIL = 29&
Const SE_ERR_DDEBUSY = 30&
Const SE_ERR_NOASSOC = 31&
Const ERROR_BAD_FORMAT = 11&

Public Sub OpenNativeApp(ByVal psDocName As String)
Dim r As Long, msg As String

r = StartDoc(psDocName)
If r <= 32 Then
    'There was an error
    Select Case r
        Case SE_ERR_FNF
            msg = "File not found"
        Case SE_ERR_PNF
            msg = "Path not found"
        Case SE_ERR_ACCESSDENIED
            msg = "Access denied"
        Case SE_ERR_OOM
            msg = "Out of memory"
        Case SE_ERR_DLLNOTFOUND
            msg = "DLL not found"
        Case SE_ERR_SHARE
            msg = "A sharing violation occurred"
        Case SE_ERR_ASSOCINCOMPLETE
            msg = "Incomplete or invalid file association"
        Case SE_ERR_DDETIMEOUT
            msg = "DDE Time out"
        Case SE_ERR_DDEFAIL
            msg = "DDE transaction failed"
        Case SE_ERR_DDEBUSY
            msg = "DDE busy"
        Case SE_ERR_NOASSOC
            msg = "No association for file extension"
        Case ERROR_BAD_FORMAT
            msg = "Invalid EXE file or error in EXE image"
        Case Else
            msg = "Unknown error"
    End Select
'    MsgBox msg
End If
End Sub

Private Function StartDoc(psDocName As String) As Long
Dim Scr_hDC As Long

Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", psDocName, "", "C:\", SW_SHOWNORMAL)
End Function
 

Users who are viewing this thread

Top Bottom