Open pdf file from info in textbox on form

khunter

Registered User.
Local time
Today, 08:15
Joined
Nov 23, 2003
Messages
25
I would like to know if it is possible to open a pdf file from access in the following way.

I have a form that contains and shows a 6 digit number. This number refers to a pdf file in a certain location. I would like to add a button on the form to "view" the pdf, instead of making the user browse to it then view it.

Is this possible? does anyone have an example that does this?

Help:)
Thanks in advance
 
you need to make an onclick event for your form item..you need the path to the file. Something like this might work.
PHP:
    Dim stAppName As String
    Dim MyPath As String
    Dim Fname As String
    
    MyPath = "C:\"
    Fname = "blah.pdf"
    
    
    
    stAppName = "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe " & MyPath & Fname
    Call Shell(stAppName, 1)
 
The filename however, is stored in the textbox on the form. It isn't static and will point to various files. I need to pass what is in the textbox of the current record to the code.....something like hmm:

fname = "current record . lngpdffileID"

Hurm, I need to take a longer look at that...

Kodo said:
you need to make an onclick event for your form item..you need the path to the file. Something like this might work.
PHP:
    Dim stAppName As String
    Dim MyPath As String
    Dim Fname As String
    
    MyPath = "C:\"
    Fname = "blah.pdf"
    
    
    
    stAppName = "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe " & MyPath & Fname
    Call Shell(stAppName, 1)
 
yes, you will need to populate my static variable with what ever is selected on the form. I just used that as an example of how to open the pdf. But don't put it in quotes!

Fname=me.form.txtFileName

something like that.
 
First of all, Thank you for the help, you have been great.
Secondly hurm...Here is what I have...I need a decent vb way to append the .pdf extension onto the filename.

It outputs what it should, it just can't find the file.

Private Sub Command6_Click()
On Error GoTo Err_Command6_Click
Dim stAppName As String
Dim MyPath As String
Dim Fname As String

MyPath = "\\users\users\khunter\Quality\Cust Notices\"
Fname = Me.Form.tblCNMaster_lngCNID
MsgBox (Me.Form.tblCNMaster_lngCNID)
'Fname = Fname
MsgBox (Fname)

stAppName = "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe" & MyPath & Fname
strMsg = "Test Output" & Chr(13) & MyPath & Chr(13) & Fname
MsgBox (strMsg)
Call Shell(stAppName, 1)



Kodo said:
yes, you will need to populate my static variable with what ever is selected on the form. I just used that as an example of how to open the pdf. But don't put it in quotes!

Fname=me.form.txtFileName

something like that.
 
Private Sub Command6_Click()
On Error GoTo Err_Command6_Click
Dim stAppName As String
Dim MyPath As String
Dim Fname As String

MyPath = "\\users\users\khunter\Quality\Cust Notices\"
Fname = Me.Form.tblCNMaster_lngCNID & ".pdf"
MsgBox (Me.Form.tblCNMaster_lngCNID)
'Fname = Fname
MsgBox (Fname)

stAppName = "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe" & MyPath & Fname
strMsg = "Test Output" & Chr(13) & MyPath & Chr(13) & Fname
MsgBox (strMsg)
Call Shell(stAppName, 1)
 
heh, we arrived at the same thing almost instantly.

However I still get the file not found.
I simplified the path to point to the local dir C:\ and still File not found error is given. The file is there sigh...

Kodo said:
Private Sub Command6_Click()
On Error GoTo Err_Command6_Click
Dim stAppName As String
Dim MyPath As String
Dim Fname As String

MyPath = "\\users\users\khunter\Quality\Cust Notices\"
Fname = Me.Form.tblCNMaster_lngCNID & ".pdf"
MsgBox (Me.Form.tblCNMaster_lngCNID)
'Fname = Fname
MsgBox (Fname)

stAppName = "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe" & MyPath & Fname
strMsg = "Test Output" & Chr(13) & MyPath & Chr(13) & Fname
MsgBox (strMsg)
Call Shell(stAppName, 1)
 
try putting a space after the .EXE" so it looks like

acrord32.exe " &
 
Got it working...Thanks again for the help. This forum has always been a great resource.

Kodo said:
try putting a space after the .EXE" so it looks like

acrord32.exe " &
 
glad it worked for you . I just learned how to do that today ;)
 
What about something like this?
Code:
Dim myFolder, myFileName, myFilePath as String
myFolder = "C:\PDF_Folder\"
myFileName = me.txtPDFNumber & ".pdf
myFilePath = myFolder & myFileName
Application.FollowHyperlink myFilePath
I tried this and it seems to work. Tried it with Word documents, Excel spreadsheets and PDF Files; they all opened fine for me.
 
Last edited:
1) Use API function to prompt user to Windows Explorer or Common Dialog Control.
2) Store path of .pdf file to the table field from Windows Explorer file selection
3) This stored path with Hyperlink technique above will resolve the issue.
 
IgorB said:
1) Use API function to prompt user to Windows Explorer or Common Dialog Control.
2) Store path of .pdf file to the table field from Windows Explorer file selection
3) This stored path with Hyperlink technique above will resolve the issue.

See my sample db in the sample db forum

http://www.access-programmers.co.uk/forums/showthread.php?t=62414

Hope this helps the situation.

Andy
 
horray! this was perfect and exactly what I needed! the code works great.
 
Hello

I have found this thread very useful, thank you very much. Would you know what I would need to do so that rather than just opening the PDF insted it just printed it?

Thanks
Iain
 

Users who are viewing this thread

Back
Top Bottom