Results 1 to 8 of 8
  1. #1
    vha7 is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2018
    Posts
    46

    How to display .pdf from links on Access form?

    Hi all,



    Access newb here. Sorry for the redundancy.

    I have a database of articles/papers and their respective links in one of my columns in my form. Instead of clicking the link and opening a page on the internet that displays my article/paper, I just want to be able to display the .pdf file in the form itself.

    To clarify - I do not plan on downloading each pdf file to store into a folder on my harddrive, and pulling out the pdfs from the source folder, as that would render to be too inconvenient and unnecessary. Additionally, I do not plan on downloading the .pdf file once it is displayed. I just want to simply be able to display the .pdf within the hyperlink so with one click, it pops up and the end user can read it.

    I am currently going about this link: https://www.experts-exchange.com/art...d-reports.html
    Specifically, what I am going for is Scenario 2 - Cache and Display. And once the pdf file is displayed, will it replace the hyperlink field or would I have to create another item on my form to designate where the pdf file is displayed?

    Any help and/or recommendations are greatly appreciated, please and thanks!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    you do NOT want to open pdf in a form, instead, open it in pdf viewer.
    this opens ANY doc in its native viewer.

    paste this code into a module. (Alt-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

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Only way to display PDF on form is with WebBrowser control.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    vha7 is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2018
    Posts
    46
    Ahh thanks for the code. And yes, thinking about it, that is exactly what I want, the file/pdf to display in its reader (i.e Acrobat or Preview, etc).

    But for the code, I have entered it in a module but it doesnt seem to work. The links that I have now are unclickable on my form.

    To clarify, does the code display the pdf first as a separate image item on the form and then once the image is clicked, it opens the pdf in a reader? (This would be preferrable)
    OPTION2: Is there a way to not display the pdf file in the form but when the link in the form is clicked on, the pdf reader is opened and the pdf file is opened there instead?
    Or does the code work by allowing the pdf reader to open once the link is clicked?

    Thanks for the clarification.

  5. #5
    vha7 is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2018
    Posts
    46
    Could you explain to me the WebBrowser control? How would I set a WebBrowser control for each link (around 1300) without having to manually and do it per single link?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Suggest you Google it. That's how I learned about - found guidance on web. Never actually used, just experimented a little.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    vha7 is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2018
    Posts
    46
    Could you clarify if this code is to display the pdf once the link is clicked on in the form? And to clarify, it is a website link and not sourcing from an internal folder.


    Additionally,

    Quote Originally Posted by ranman256 View Post
    Private Function StartDoc(psDocName As String) As Long [/code]
    I run the code and it says that this line is "Ambigous:~". Help please?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Make sure procedure and module do not have same name.

    Code should open a PDF file in Adobe. Not sure can handle web link.

    Maybe this code will be useful http://allenbrowne.com/func-GoHyperlink.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access and Google links.
    By snowboarder234 in forum Access
    Replies: 6
    Last Post: 03-14-2018, 11:45 PM
  2. Replies: 6
    Last Post: 09-11-2015, 05:05 AM
  3. Replies: 3
    Last Post: 03-17-2014, 10:23 AM
  4. Issue with Table Links in MS Access 2010
    By sesling in forum Access
    Replies: 2
    Last Post: 12-24-2012, 08:14 AM
  5. Problems opening links from access
    By anguyen in forum Access
    Replies: 0
    Last Post: 09-22-2009, 06:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums