Results 1 to 7 of 7
  1. #1
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402

    Viewing a PDF in a form

    Hi All



    i have this code that runs on my forms on load event


    Code:
    Private Sub Form_Load()
        Dim strPDFLink As String
        Me.Full_Name = Forms!frmCustomersEditOrders!FullName
        Me.Date_Of_Order = Forms!frmCustomersEditOrders![Date Of Order]
        DoCmd.OpenReport "rptCustomerInvoice", acViewPreview, "", "", acHidden
        DoCmd.OutputTo acOutputReport, "rptCustomerInvoice", acFormatPDF, (DLookup("Path", "tblLinks", "DocumentID = 1")) & "\customers" & "\" & Me.Full_Name.Value & "\Invoices" & "\" & "Invoice Dated" & " " & Format(Date_Of_Order, "dd-mm-yyyy") & ".pdf", False
        DoCmd.Close acReport, "rptCustomerInvoice", acSaveNo
        strPDFLink = (DLookup("Path", "tblLinks", "DocumentID = 1")) & "\customers" & "\" & Me.Full_Name.Value & "\Invoices" & "\" & "Invoice Dated" & " " & Format(Me.Date_Of_Order, "dd-mm-yyyy") & ".pdf"
    
    
        Me.WebBrowser0.Object.Navigate strPDFLink
    
    
    End Sub
    this works really nicely and opens the pdf as expected, however when the form closes acrobat reader opens and hangs for about 15 seconds making the application unusable

    is there a way to stop Acrobat reader opening up when the form closes?

    many thanks

    Steve

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Paste this code into a module, and it will open ANY file in its native application.

    usage: OpenNativeApp ME.txtBox
    if the file is myFile.pdf, will open it in acrobat
    if the file is myFile.doc, it will open the doc in Word
    if its just a file path, it will open in file explorer.
    etc..


    Code:
    'Attribute VB_Name = "modNativeApp"
    '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

  3. #3
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Ranman256

    that looks interesting, i will give that a go

    many thanks

    steve

  4. #4
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Ranman256

    i get sub or function not defined and the code stops

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


    r = startdoc(psDocName)
    If r <= 32 Then


    does this have to be declared anywhere
    many thanks

    steve

  5. #5
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    oop, sorry, that was the bottom of the code and i missed it.
    paste into module:


    Code:
    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

  6. #6
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Ranman256

    thats brill, will try this out later and let you know how it goes.

    once again

    many thanks

    steve

  7. #7
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Ranman256

    thanks for the code mate, works like a charm many thanks


    steve

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

Similar Threads

  1. Opening main form after viewing a report.
    By Robert2150 in forum Access
    Replies: 13
    Last Post: 05-26-2015, 10:03 AM
  2. Make MS Access Form Online and viewing in browser
    By pritesharyan in forum Access
    Replies: 4
    Last Post: 03-22-2015, 11:30 AM
  3. Problems in viewing my form
    By aim_shaws in forum Forms
    Replies: 4
    Last Post: 06-08-2013, 08:08 AM
  4. Replies: 5
    Last Post: 12-22-2011, 01:12 PM
  5. Viewing Form via Switchboard
    By MollyB in forum Forms
    Replies: 1
    Last Post: 05-20-2010, 10:05 AM

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