tastycanofmalk
tastycanofmalk

Reputation: 628

Print entire list of PDF files

I'm in the process of creating a database with many chemicals & associated .pdf files with their information.

Each chemical has a unique ID and in the same row has a link to the .pdf file on the network.

In addition, each chemical has a location assigned to it.

My goal is to be able to print all .pdf associated with chemicals in each location.

For example:

ID          Chemical          Location         PDF-link
1           Acetone           Lab-A            A:/folder/1.pdf
2           Fire              Lab-A            A:/folder/2.pdf
1           Acetone           Lab-B            A:/folder/1.pdf
3           Sponge            Lab-B            A:/folder/3.pdf
4           Candy             Lab-B            A:/folder/4.pdf

If I specify Lab-A, I would like it to print both PDFs: 1.pdf, 2.pdf.

If I specify Lab-B, I would like it to print those respective .pdf files.

Of course I also want to be able to print all of them as well, but I think if I figure out how to do the above, I can manage to do this.

Thanks for any help.

Upvotes: 1

Views: 791

Answers (2)

user2204315
user2204315

Reputation:

Have a look at this: http://www.jpsoftwaretech.com/open-or-print-files-in-vba/

I have used it successfully by putting a command button on a form e.g:

In a module I put this:

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

The OnClick event for one of my command buttons is:

PathName1 = "Full path.pdf"
PathName2 = "Full path.rtf"

ExecuteFile PathName1, printfile
ExecuteFile PathName2, printfile

You'll need to set up a Select Case or If Then Else statement to print what you actually want.

Upvotes: 2

Albert D. Kallal
Albert D. Kallal

Reputation: 49119

The code to do this will look like this:

Sub PrintMyPdf()

  Dim rst     As DAO.Recordset
  Dim strSQL  As String

  strSQL = "select * from tblChem where Location = '" & Me.txtLocation & "'"

  Set rst = CurrentDb.OpenRecordset(strSQL)
  Do While rst.EOF = -False
     Call PrintOnePdf(rst![PDF-link])
     rst.MoveNext
  Loop
  rst.Close

End Sub

Sub PrintOnePdf(strF As String)

  CreateObject("Shell.Application").Namespace(0).ParseName(strF).InvokeVerb ("Print")

End Sub

The above code assumes you have a text box on the form of txtLocation, and then the above code can be placed behind a button click even (or simply call the above code from the button click even.

The above code assumes you have some type of PDF reader for the printing to occur.

Upvotes: 2

Related Questions