Printing Hyperlinked objects

  • Thread starter Thread starter Les Desser
  • Start date Start date
L

Les Desser

I have links to documents (pdf) in a particular table and wonder if I
can print the documents from code.

For example, when producing a report of expenses (invoices received)
that need to be paid, I would also like to print copies of any invoices
that have been scanned and linked to the expenses.

Thanks.
 
As of XP SP2 ShellExecute wants the path separate from the filename.
Otherwise yu get "File Not Found"

This variation splits the file and path. I've tested it
with various files residing in "My Documents"
Note: .PDF ->Acrobat Reader stays open on the taskbar after printing,
.DOC -> fine, Word closes after printing
.TXT -> fine, Notepad closes after printing

' --------- mod_MyPrintInterface -------------------------------------
Option Compare Database
Option Explicit

' define external API function --------------
Private 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 Sub MyPrintInterface(hWnd As Long, str_FullFilePathName As String)
Dim long_RetVal As Long
Dim I As Integer, L As Integer, LastSlash As Integer
Dim str_Filename As String
Dim str_Path As String

L = Len(str_FullFilePathName)
LastSlash = 0
For I = 1 To L
If Mid$(str_FullFilePathName, I, 1) = "\" Then LastSlash = I
Next I
If LastSlash > 0 Then
str_Filename = Mid$(str_FullFilePathName, LastSlash + 1)
str_Path = Mid$(str_FullFilePathName, 1, LastSlash)
Else
str_Filename = str_FullFilePathName
str_Path = ""
End If
long_RetVal = ShellExecute(hWnd, "Print", str_Filename, "", str_Path, 0)
' Debug.Print long_RetVal
' in my testing, long_RetVal was 42 on success
End Sub
---------------- end mod_MyPrintInterface -----------

In your "calling" form, perhaps in item_Click() event...


Private Sub my_hyperlink_item_Click()
MyPrintInterface Me.Form.hwnd, Me.my_hperlink_item.Value
End Sub
 
You don't need to worry. If the path and filename are separate the API will
work going way back, probably even to Access 2.0. Having the full path and
filename in the filename argument with no path worked but wasn't following
the API's specifications. Apparently it opened up a security hole that MS
plugged in SP2.

Les Desser said:
NKTower said:
As of XP SP2

[...]

Thanks for that.

How do I tell whether Access is running in XP or an earlier version of
windows?
 
NKTower said:
You don't need to worry. If the path and filename are separate the API
will work going way back, probably even to Access 2.0. Having the
full path and filename in the filename argument with no path worked but
wasn't following the API's specifications. Apparently it opened up a
security hole that MS plugged in SP2.

Thank you.
 
Back
Top