Load Local PDF into Webbrowser (1 Viewer)

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:58
Joined
May 21, 2018
Messages
8,992
In relation to this thread

I wanted to demo this. So I select a report and export to the current folder. That works fine. Then I want to display that in the web browser, and sometimes it works but most of the time it does not. The problem is not with Access but with adobe.

Code:
  On Error GoTo CmboReport_AfterUpdate_Error
  Dim rptName As String
  Dim FullPath As String
  Dim cs As String
  If Not IsNull(Me.CmboReport) Then
    rptName = Me.CmboReport
    FullPath = CurrentProject.Path
    FullPath = FullPath & "\" & rptName & ".pdf"
    exportPDF rptName, FullPath
    cs = "= " & Chr(34) & FullPath & Chr(34)
   
    Me.wbBrowser.ControlSource = cs
    DoEvents
   
    'Do While Me.wbBrowser.Object.Busy Or Me.wbBrowser.Object.ReadyState <> 4
    '  DoEvents
    'Loop
   
    Me.wbBrowser.Object.Refresh
  End If
    On Error GoTo 0
    Exit Sub
CmboReport_AfterUpdate_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CmboReport_AfterUpdate, line " & Erl & "." & vbCrLf & "ControlSource " & cs
End Sub

Private Sub exportPDF(ReportName As String, FullPath As String)
    On Error GoTo exportPDF_Error
  Dim fileName As String
  DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, FullPath
    On Error GoTo 0
    Exit Sub
exportPDF_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure exportPDF, line " & Erl & "."
End Sub


This is the error from Adobe. Nothing is trapped in VBA
Problem.png


But sometimes it works and loads. Only certain reports work.

PDFReport.png


I tried doing the do events loop, but I believe it never exits and nothing ever renders.

Any Ideas? Thanks.
 

Attachments

Last edited:
I do not have Adobe on my laptop, but you have not supplied the exportPDF code?, so I can see if it works for me?
Can you please supply a dB that I can just run for you?
 
All the reports open fine for me. There is some type of pop up that flashes too fast to read before it loads.
I cycled through them all 4 times.
 
I do not have Adobe on my laptop, but you have not supplied the exportPDF code?, so I can see if it works for me?
Can you please supply a dB that I can just run for you?
Unrecognised DB for me. Too new, sorry. :(
 
Works all the time every time with Nitro PDF pro... HOWEVER
If i select a report it works, if i then select a different report it works but if i select a report then select the same report again i get an error Invalid Folder Path, Please Update Code
 
Last edited:
Pretty sure the culprit is always Adobe's activeX plugin... That thing doesn't work for me even if I load directly to IE without a web browser control.

Anyways, you might still have the DocumentComplete event, you could try setting the control source from there or use something else for loading PDF files. Like a JS library that works with IE. Or the new browser control, if you have it.
 
@Gasman,
I added the export code to the original thread.
 

Users who are viewing this thread

Back
Top Bottom