Results 1 to 3 of 3
  1. #1
    Ajz1971 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    7

    Print off query results?

    Hi There,
    I’m not sure if I’m in the right section here? But what I’m looking for is a way to do the following…


    I have a query that gives me a list of Linked PDF Files (C:/Policies/Policy1.PDF…. C:/Policies/Policy2.PDF etc…) what I would like to do is be able to print off all documents automatically using VBA code that I can attach to the on click of a button…Is this possible?

    The query is named 'Staff Query'... The column of linked files is 'Feild2' ....I do not need to view the PDF's, and Adobe PDF reader path is "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"





    Thanks in advance for any feedback

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Cycle thru the recordset,sending each to the printer....
    Code:
    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long
    
    
    sub btnPrintFiles_click()
    Set rst=currentDb.openrecordset("qsMyQuery")
    with rst
       While not .eof
           call Print1File( .fields("FilePath") )         'Send the field to the printer
           .moveNext
       Wend 
    end with
    set rst = nothing
    end sub
    
    Public Function Print1File( FileName As String)
    On Error Resume Next
    Dim X As Long
    X = ShellExecute(0, "Print", FileName, 0&, 0&, 3)
    End Function

  3. #3
    Ajz1971 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    7
    Hi ranman256, thanks for the reply

    I have put your code in and changed parts of the codes to suit...not sure if i've done this right tho? I get a compile error on shellexecute?

    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long


    Sub Image5_Click() 'form image which user will click to print pdf's
    Set rst = CurrentDb.OpenRecordset("Staff Query") 'put my query here?
    With rst
    While Not .EOF
    PrintFile Me.Hwnd, .Fields("Field2") 'put the field which holds the list of paths here?
    .MoveNext
    Wend
    End With
    Set rst = Nothing
    End Sub

    Public Function PrintFile(formname As Long, FileName As String)
    On Error Resume Next
    Dim X As Long
    X = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
    End Function

    Not sure where I'm gong wrong here, any feedback will be great help

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

Similar Threads

  1. Replies: 5
    Last Post: 07-29-2014, 01:05 PM
  2. Replies: 6
    Last Post: 03-01-2014, 07:07 AM
  3. Replies: 5
    Last Post: 05-21-2013, 02:21 PM
  4. Replies: 3
    Last Post: 05-02-2013, 10:36 AM
  5. Replies: 6
    Last Post: 05-14-2012, 07:24 AM

Tags for this Thread

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