Results 1 to 9 of 9
  1. #1
    Euler is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    62

    Display PDF on Access report

    Hello,

    I'm trying to display a PDF on an Access report. I've researched the issue but I can't get it to work. Most people say to use the Web Browser ActiveX control. Which I've done but nothing appears. I've also tried using the Adobe Acrobat DC Browser ActiveX control but with no joy either.

    I have the location of the PDF in an Access table as an attachment. Here's my code to fetch and display it using the Web Browser ActiveX control:

    Private Sub Report_Load()
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim rstChild As DAO.Recordset


    Dim FilePath As String
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("SELECT tblXML.PK, tblXML.XMLPath, tblXML.FileName, tblXML.LoadDate, tblXML.AttachedFile FROM tblXML WHERE (((tblXML.PK)=1));")
    Set rstChild = rst.Fields("AttachedFile").Value
    FilePath = "C:\Temp" & "\Preview.pdf"
    If (Dir(FilePath) <> "") Then Kill FilePath
    rstChild.Fields("FileData").SaveToFile FilePath
    Me!PreviewBrowser.Navigate (FilePath)
    rst.Close
    End Sub

    This code extracts the PDF and saves it to a temporary location where it should be picked up with the "Navigate" function. The file is created but nothing appears in the control.

    Can someone please help me with this?

    Thank you very much.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I think what you need is the bound object frame; control source set to the attachment field. I've never used it because I would not put attachments in a table. The web browser control was designed to load web pages. I can only guess that to load files with the wb control, your url must start with file:/// and not just the drive letter, which is what I surmise you're doing.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    I wouldnt. You loose detail resolution.
    Just open the pdf natively in its own app.

  4. #4
    Euler is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    62
    Quote Originally Posted by Micron View Post
    I think what you need is the bound object frame; control source set to the attachment field. I've never used it because I would not put attachments in a table. The web browser control was designed to load web pages. I can only guess that to load files with the wb control, your url must start with file:/// and not just the drive letter, which is what I surmise you're doing.
    Thank you very much for replying.

    I tried using the bound object frame but that doesn't work; maybe because attachments in tables seem to be like multi-valued fields. I don't need to have the PDF in a table. If I can get the bound object frame to work without the attachment field, that would be OK.

    I also tried using an unbound object frame and it worked but it seems that I have to designate the location of the PDF when I create the frame. I also don't know how I can programmatically change the file location for each different report. I will keep investigating, however, since at least I got a result using the unbound object frame.

    Thanks again for your help.

  5. #5
    Euler is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    62
    Thank you for replying.

    I really don't have a choice. It's what the customer insists on.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You can set the source in code any time after making the initial choice. It's the same for an image control when you're linking (not embedding) the picture. Navigate to the file, choose it, then alter the property via code as needed.
    I have read that attachment fields are a form of mvf. No idea why that would be seeing as how only one item can be stored in that field per record?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Euler is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    62
    You're right. I was embedding, not linking. When I link I can change the "Source Doc" property at runtime using code.

    I also found that I could save the PDF as an OLE object in the table and bind the frame object to it. I don't know if that's a good idea because it might bloat the database.



    Here you can see that the attachment has three fields associated with it: "FileData", "FileName" and "FileType". The actual image is in "FileData" but that field is its own database with three fields in it. Using the attachment as the control source doesn't get me to the "FileData" field. At least, it hasn't worked for me.

  8. #8
    Euler is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2015
    Posts
    62
    Sorry. The screen print didn't show up.Click image for larger version. 

Name:	Capture.JPG 
Views:	11 
Size:	17.9 KB 
ID:	44515

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    That is a mv field. Out of curiosity, you're saying that AttachedFile.FileData as the control source doesn't load the object? I wouldn't know because IMO any kind of mv field is to be avoided, and if that field is for attachments, then yes, it tends to rapidly bloat the db.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. access, queries for report display
    By akika in forum Queries
    Replies: 4
    Last Post: 01-21-2021, 06:57 AM
  2. Replies: 3
    Last Post: 11-09-2019, 04:27 AM
  3. Replies: 3
    Last Post: 10-09-2017, 09:12 PM
  4. Replies: 6
    Last Post: 10-30-2012, 11:36 AM
  5. Replies: 7
    Last Post: 10-18-2012, 12:49 PM

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