Printing linked files (word, pdf etc) (1 Viewer)

anb001

Registered User.
Local time
Today, 02:34
Joined
Jul 5, 2004
Messages
197
In order to open files with a cmd button, I use below code:

The module:
Code:
Option Compare Database
Option Explicit

Public Const SW_HIDE = 0
Public Const SW_NORMAL = 1
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_MAX = 10
Public Const SW_SHOWDEFAULT = 10

' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'


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


Public Function bimShellOpenFile(strFilePath As String, lngShowCmd As Long) As Long
'
' opens the file passed by calling windows
' the file should be opened into the app associated with the files type
'

Dim r As Long
Dim hwnd As Long

r = ShellExecute(hwnd, "open", strFilePath, "", "", lngShowCmd)

bimShellOpenFile = r


End Function

Code for cmd button:
Code:
Private Sub cmdProcedurePath_Click()

Dim retval As Variant

If Me.txtProcedurePath > "" Then
    
    retval = bimShellOpenFile(Replace(Me.txtProcedurePath, "%dir%", Me.txtDatabasePath), vbNormalFocus) ' vbNormalFocus  True
Else
   MsgBox "There is no file to view."

End If

End Sub

This works fine, and I can choose a relative link (relative to the database) or a direct link (c:\folder\file.docx).

I would like to proceed a bit, and also print the linked files from a button, and preferably without opening the files, if possible. Or perhaps, as Windows when right-clicking on af file and click Print (opening the file, print it, and close it again). I would also like to be able to write wnated copies in a text box, and then that specific number of copies should be printed.

Is this at all possible?

EDIT: Forgot to include, that I can also open files on a server location, like:
[http://sirius-offline/DKOs/M-CPH-1171-17987_EN.dot]
and I would of course also like to be able to print them.
 
Last edited:

PeterF

Registered User.
Local time
Today, 02:34
Joined
Jun 6, 2006
Messages
295
The opening of the file is prepared in this line:
Code:
r = ShellExecute(hwnd, "open", strFilePath, "", "", lngShowCmd)
To print a file change it to:
Code:
r = ShellExecute(hwnd, "print", strFilePath, "", "", lngShowCmd)

To hide the program window change "vbNormalFocus" in the calling function to "vbHide"
 

anb001

Registered User.
Local time
Today, 02:34
Joined
Jul 5, 2004
Messages
197
PeterF,

Thank you. That helped a bit of the way.

I can print files with this, shich are stored on a computer/network drive (e.g. c:\folder\file.pdf).

But when it comes to files placed on our http server, then nothing happens when I click the print button. In the VBA window, you can see it says "running" in the top of the program window, but nothing is happening. No errors, but also no print.

As mentioned in previous post, one http link on our web server could be:
[http://sirius-offline/DKOs/M-CPH-1171-17987_EN.dot]

There are also pdf files and Word docx files.

I can e.g. create a shortcut to the file on my computer, and then right-click that shortcut, and then click print. Is there any code which will do that (e.g. print) in Access/VBA??

EDIT: I forgot to mention, that I can open files from the web, using the "open" menthod, but it won\t print.

Thanks.
 
Last edited:

anb001

Registered User.
Local time
Today, 02:34
Joined
Jul 5, 2004
Messages
197
I found that I can use URLDownloadToFile, and then print it using ShellExecute Function.

The only thing I would ask now is, can I somehow state that I want more than one copy printed?
 

Users who are viewing this thread

Top Bottom