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

    Print all PDF Documents in a folder

    Hi Guys

    is this possible to do?
    I have a folder located here (c:\testsheets)

    this folder contains hundreds of part numbers, all part numbers are 10 characters long the only difference between them is the (-10,20,30) at the end


    AA01FG2056-10
    AA01FG2056-20

    CA52EE0990-10
    CA52EE0990-20
    CA52EE0990-30

    I have a form frmPartSelection that has a combobox called (PartsCBOBox)with all the part numbers listed

    what I would like to happen is this

    when a user selects a part number from the combo box, and clicks on a button called "print" all the PDF documents in the test sheet folder located here (c:\testsheets) are printed so for example



    the user selects

    BB99XZ1234, the system prints from the test sheet folder
    BB99XZ1234-10
    BB99XZ1234-20
    BB99XZ1234-30

    I am really struggling to get my head around how to do this, any help would be brill

    many thanks

    steve

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    im not sure where you get the # part.

    Code:
    vFile = "c:\testsheets\" & me.PartsCboBox & "-" &  iNo & ".pdf" 
    docmd.OutputTo acOutputReport ,"report",acFormatPDF,vFile

  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

    many thanks for the heads up will take a look at that
    steve

  4. #4
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Steve,

    What Ranman256 suggested is for saving an Access report to a PDF in the folder.

    What I think you want is to print all the matching PDF files stored in the folder to the default printer.

    Would you please clarify what you want to do.

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

    your correct what I want to do is physically print the matching pdfs, basically print every PDF that starts with the first 10 characters stored in the c:\test sheet folder to the default printer when a button is pressed using the buttons on click event

    is this possible to do?

    steve

  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

    I have used this code that you have previously posted (Not sure how I missed this) opps

    on the command button I use this
    Code:
    Private Sub Command2_Click()
    PrintAllFilesInDir "c:\testsheets"
    End Sub
    and this is the code that prints the PDF's

    Code:
    Public Sub PrintAllFilesInDir(ByVal pvDir)
       Dim vFil As String, vTargT
       Dim i As Integer
       Dim fso
       Dim oFolder, oFile
       Dim vOutFile   On Error GoTo errImp
       If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set oFolder = fso.GetFolder(pvDir)
    
       For Each oFile In oFolder.Files
          vFil = pvDir & oFile.Name
          If InStr(vFil, ".pdf") > 0 Then      'ONLY DO PDF FILES
             'Print vFil
             Call ShellExecute(0, "print", vFil, "", "", 1)
          End If
       Next
    
       Set fso = Nothing
       Set oFile = Nothing
       Set oFolder = Nothing
       MsgBox "Done"
       Exit Sub
    errImp:
       MsgBox Err.Description, vbCritical, "clsImport:ImportData()" & Err
       Exit Sub
       Resume
    End Sub
    This works really well printing all the PDF's from the (c:\testsheets) folder, would you have any idea how I could modify the above to only print the part numbers that match the part number from the combo box called (PartsCBOBox)

    Im guessing that I would have to amend the for each section, to reference the combo box but I cant seem to work out how to do this,

    Steve

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You already do it - "If InStr(vFil, ".pdf") > 0 Then 'ONLY DO PDF FILES". Right underneath copy this line of code and replace the ".pdf" with your part number. Don't forget to add another End If.

  8. #8
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi aytee111
    That's brilliant, many thanks
    steve

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

Similar Threads

  1. How to print off multiple word documents
    By Ajz1971 in forum Access
    Replies: 10
    Last Post: 01-20-2017, 07:57 AM
  2. Need access vba to Print all pdf from a fix folder
    By Khatuaaccess in forum Access
    Replies: 9
    Last Post: 08-07-2016, 08:35 AM
  3. vba to print all pdfs from a folder
    By Khatuaaccess in forum Access
    Replies: 1
    Last Post: 08-01-2016, 05:17 AM
  4. Replies: 10
    Last Post: 09-09-2015, 03:25 AM
  5. Replies: 2
    Last Post: 07-01-2014, 07:24 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