Results 1 to 10 of 10
  1. #1
    Danny2024 is offline Novice
    Windows 8 Access 2016
    Join Date
    Feb 2018
    Posts
    9

    Printing pdf document from a folder when button clicked


    Hi

    I want a pdf document to print off at the same time as a report when a button is clicked on a form

    The PDF document is located in a folder on the N drive N:\QA\Inspection Plans\Ballooned Drawings

    A text box on my form will contain the name of the document that needs printing, the textbox is called Partnumber_print

    So for example if Partnumber_print = FW80603, when the button is clicked I want report "Rep_Insp_Plan_Print_All" & FW80603.pdf to print off

    The report works fine, as it is within the access database. It is just trying to understand how I link the PDF file to print also from the folder located elsewhere

    The button currently has the following code:

    Private Sub Command43_Click()
    DoCmd.SelectObject acReport, "Rep_Insp_Plan_Print_All", True
    DoCmd.PrintOut , , , , 1
    End Sub

    Thanks in advance

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    it looks like your selecting a report to print....
    so
    do you want to 'print' the report , creating the PDF file AND print it to the printer,?
    or
    take the existing pdf in the path, and send THAT to the printer?

  3. #3
    Danny2024 is offline Novice
    Windows 8 Access 2016
    Join Date
    Feb 2018
    Posts
    9
    Hi Ranman

    The report is what we call an inspection plan, this is what I want our inspector to work to and all the data is contained in the database tables, I just put that in a report and print it using the code shown. This works absolutely fine.

    The PDF is a drawing that the inspector will look at while inspecting the product in line with the report (Inspection Plan) that he has printed

    Currently he has to print the report from the database (Inspection Plan) and then go find the folder on the drive that holds the drawing and print it from there

    I would like to be able to get it so when he clicks print for the report from the database, the PDF drawing prints off automatically aswell so he would not have to go and find it separate

    Hence the button when clicked prints both documents and removes the time taken that would require manually finding and printing the drawing

    Hope that makes sense

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Access can open the PDF from the hyperlink but then sending that PDF to printer requires manipulating Adobe Acrobat. Review https://www.techwalla.com/articles/h...int-a-pdf-file

    Here's the code from that link. Haven't tested yet. Crud! Just tried to compile and errors on FileLocked() function. The link doesn't provide the code for this!!! There are other issues but so far only thing I can find that offers any clue of how to print external file.
    Code:
    Sub OpenPDF()
    Dim strPDFFileName As String
    'Edit to add the full filename to the PDF file that you want to open
    strPDFFileName = "C:\examplefile.pdf\"
    'This next function checks to see if the file isn't already open
    If Not FileLocked(strPDFFileName) Then
        'If it returns False, then continue opening the PDF file
        Documents.Open strPDFFileName
    End If
    End Sub
    
    Sub PrintPDF(strPDFFileName As String)
    Dim sAdobeReader As String
    'This is the full path to the Adobe Reader or Acrobat application on your computer
    sAdobeReader = "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe\"
    RetVal = Shell(sAdobeReader & "/P\" & Chr(34) & sStrPDFFileName & Chr(34), 0)
    End Sub
    
    Sub TestPrintPDF()
    'Call the open function first so that the PDF can open before printing
    Call OpenPDF
    'Now call the print function so that the PDF can be printed
    Call PrintPDF
    End Sub
    Last edited by June7; 02-15-2018 at 01:16 AM.
    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.

  5. #5
    NTC is offline VIP
    Windows 10 Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    Part 1: if you have the path to the PDF in the db table - then you can launch it at least - - that much saves them from having to browse to find it at least.

    Part 2: J7 has given some Adobe code to then send it to print - - wasn't sure that was even possible but worth a try I suppose.....

  6. #6
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Select a file:
    Code:
    Dim f As Object
    Dim strFile As String, strfolder As String
    Dim varItem As Variant
    
    Set f = Application.FileDialog(1)
           f.AllowMultiSelect = False 
        
        If f.Show Then
            For Each varItem In f.SelectedItems
                strFile = Dir(varItem)
                strfolder = Left(varItem, Len(varItem) - Len(strFile))
            Next
        End If

  7. #7
    Danny2024 is offline Novice
    Windows 8 Access 2016
    Join Date
    Feb 2018
    Posts
    9
    All

    Thanks for the help

    Finally managed to get it to open using the code below

    Private Sub Command52_Click()
    Shell "C:\Program Files (x86)\Foxit Software\Foxit Reader\foxitreader.exe M:\test.pdf", vbNormalFocus
    End Sub

    Still struggling on how to print this object though automatically?

    half way there at least lol

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Found another:

    Code:
      
    Sub PrintPDF(strFile As String)
    Dim lngRes As Long
    lngRes = ShellExecute(0, "Print", strFile, "", "", 3)
    End Sub
    Dang, it worked!!!
    But it leaves Acrobat on the taskbar. CLOSE or QUIT not an operation available to ShellExecute. Only way I've found to shut down an application is to terminate all its processes:

    Code:
    strComputer = "."
    strProcessKill = "'msaccess.exe'"
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )
    For Each objProcess in colProcess
        objProcess.Terminate()
    Next
    Last edited by June7; 02-16-2018 at 06:14 AM.
    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.

  9. #9
    Danny2024 is offline Novice
    Windows 8 Access 2016
    Join Date
    Feb 2018
    Posts
    9
    Thanks June7

    Finally managed to crack this, one of my colleagues just gave me a copy of an Access 2007 programming book he had hidden away and it turned out to be really simple

    The code below worked

    Private Sub Command51_Click()
    Dim objShell As Object
    Set objShell = CreateObject("Shell.Application")

    objShell.ShellExecute "M:\test.pdf", , , "print", 1
    End Sub

    The only annoying bit is that foxit stays open after printing but I can live with that

    Thanks everyone for your help and suggestions

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    We must have made same discovery about same time.
    But notice I do not declare and set a Shell object.
    Did some edits on my earlier post as you were posting.
    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. Replies: 3
    Last Post: 02-10-2016, 01:46 AM
  2. button to scan a document to pdf and save to folder
    By charlieb in forum Programming
    Replies: 2
    Last Post: 04-20-2015, 09:40 AM
  3. Replies: 3
    Last Post: 04-16-2014, 04:29 PM
  4. Replies: 1
    Last Post: 08-02-2013, 10:38 AM
  5. Replies: 3
    Last Post: 02-22-2013, 06:41 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