Joining String and printing external file

Sam Summers

Registered User.
Local time
Today, 20:10
Joined
Sep 17, 2001
Messages
939
Hi Guys,

Been trying this one all day. I've tried playing with a few things from the forum and i'm nearly there. I just need a wee bit of expert help.

I have a form that displays a persons details and on it i have a command button, and all i want to do is to print a pdf file (or maybe jpg files) that are in a certain folder on a network.
To do this i must reference the employees name folder and then there name file.

This is what i have got so far:

Dim I As String
Dim S As String

Me.First_Name.SetFocus
I = Me.First_Name.Text
Me.Surname.SetFocus
S = Me.Surname.Text

Application.FollowHyperlink "F:\Personnel Certs\( & ""& )\( & "" & ).pdf"
SendKeys "%(FP)"
SendKeys "~", True

***************************************************

All is good until the Application line where i am trying to join the two text strings from the First_Name and Surname Textboxes.

The values for I and S are working.

The path to the folder is: G:\Personnel Certs\"persons name"\"persons name".pdf

The other method i could and may use is the command dialog which will give the user the choice of file to print but if i use this i want it to access the persons name folder anyway.

Many thanks in advance
 
I suggest that you avoid using the SendKeys method.

My Browse [Find a directory or file] sample will show you how to allow the user to browse for thier file. Just add the below code to print the selected file...

Code:
Public Function PrintFile(sFileName As String)
On Error GoTo Err_PrintFile

    PrintFile = ShellExecute(Application.hWndAccessApp, "Print", sFileName, "", "C:\", 0)

Exit_PrintFile:
    Exit Function

Err_PrintFile:
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_PrintFile

End Function
 
Thanks for that.

Is there any way that i can onclick, print the file direct as opposed to browsing for it?
Obviously it would have to find the file in the location by the persons first name and surname.
 
Just create the string and pass that string to the function I gave you.
 
I'm trying that but i dont have a clue what i'm really doing. I've been trying for 4 hours now to run the function in the OnClick event of a button but i dont know what i'm doing.

I've created this function as a module:-

Option Compare Database
Option Explicit

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 PrintFile(sFileName As String)
On Error GoTo Err_PrintFile

Dim I As String
Dim S As String

Forms!Employee!First_Name.SetFocus
I = Forms!Employee!First_Name.Text
Forms!Employee!Surname.SetFocus
S = Forms!Employee!Surname.Text

sFileName = "F:\Personnel Certs\(,""&(,"")\(,""&(,"").pdf"

PrintFile = ShellExecute(Application.hWndAccessApp, "Print", sFileName, "", "C:\", 0)

Exit_PrintFile:
Exit Function

Err_PrintFile:
MsgBox Err.Number & " - " & Err.Description

End Function


But i cant seem to call it from the button?????
 

Users who are viewing this thread

Back
Top Bottom