Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlink to PDF Files

Status
Not open for further replies.

TriniGal

Programmer
Sep 28, 2005
84
US
Can someone please tell me what I'm doing or not doing wrong?

I have the following module:

Code:
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 nshowcm As Long)

Sub ShellToFile(strFolder As String, strFile As String, _
    strExtension As String, ByVal lngHwnd As Long)

    Dim lngRetVal As Long
    Dim strPath As String
    
    If Right(strFile, 3) <> strExtension Then
        strFile = strFile & "." & strExtension
    End If
     
    If Right(strFolder, 1) <> "\" Then
        strFolder = strFolder & "\"
    End If
    
    strPath = strFolder & strFile
    
    lngRetVal = ShellExecute(lngHwnd, "open", strPath, _
        vbNullString, CurDir$, 1)
    If lngRetVal < 32 Then
        MsgBox "Unable to open file " & strPath, vbInformation, "Warning"
    End If
    
End Sub

Then I have this attached to the field which contains the name of the file in text:

Code:
Private Sub Ctl2009_REPORT_Click()
On Error GoTo Err_Ctl2009_REPORT_Click


ShellToFile "V:\FCC Form 320 Reports\", Me.Ctl2009_REPORT, "pdf", hwnd

Exit_Ctl2009_REPORT_Click:
Exit Sub

Err_Ctl2009_REPORT_Click:
    MsgBox Err.Description
    Resume Exit_Ctl2009_REPORT_Click

End Sub

I'm getting the error "Unable to open...."

Please help.


 
Why not simply use the Application.FollowHyperlink method ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

From what I've read, that doesn't work for .pdf files. Am I mistaken? If I am, how would I go about doing that?

Thanks.
 
Provided that the extension is parts of the filename in the control's value:
Application.FollowHyperlink "V:\FCC Form 320 Reports\" & Me!Ctl2009_REPORT

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,

Background information:

-database was created in Access 2003, I am running Access 2007
-the users have Read-Only access to the folder where the .pdf files are stored
-it is a hyperlink datatype
-in the form where it says "Is Hyperlink" I have YES, where it says "Display As Hyperling" I have ALWAYS
-when I click on the link, the .pdf report opens up for me
-when one of the user open it up they first get
Cannot open the specified file.
-the user clicks "OK"
-then gets the message
Unable to open V:\Engineering\FCC Form 320 Reports.... Cannot open the specified file.

This is my exact code

Code:
Private Sub Ctl2009_REPORT_Click()
On Error GoTo Err_Ctl2009_REPORT_Click


Application.FollowHyperlink "V:\Engineering\FCC Form 320 Reports\" & Me![2009 REPORT 1]

Exit_Ctl2009_REPORT_Click:
Exit Sub

Err_Ctl2009_REPORT_Click:
    MsgBox Err.Description
    Resume Exit_Ctl2009_REPORT_Click

End Sub
 
TriniGal,

What shows in Me![2009 REPORT 1]?

Does it include the file extention for the file, or not, as PHV asked.

If not, then change your code to this:
Code:
Private Sub Ctl2009_REPORT_Click()
On Error GoTo Err_Ctl2009_REPORT_Click


Application.FollowHyperlink "V:\Engineering\FCC Form 320 Reports\" & Me![2009 REPORT 1] [B][BLUE]& ".pdf"[/BLUE][/B]

Exit_Ctl2009_REPORT_Click:
Exit Sub

Err_Ctl2009_REPORT_Click:
    MsgBox Err.Description
    Resume Exit_Ctl2009_REPORT_Click

End Sub
 
Cannot open the specified file.
Are you sure the user has a PDF reader installed ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Something just dawned on me, so before I go any further I should ask a couple questions.

What should be stored in the table in that field?

This is what I have right now.
-the table and the form field looks like 000001-Bronx, NY (Text to display from the Insert Hyperlink Menus)
-the actual address of the hyperlink is V:\Engineering\FCC Form 320 Reports\000001-Bronx, NY

Is this right?
 

What about the .pdf extension?
You also failed to answer PHV's question.


Randy
 
Sorry,

Yes, it had the extension eg. 000001-Bronx, NY.pdf
 
Here is the code from my actual database which is a membership for a non profit club. The pdf is instructions for using the database.

It first looks for a copy on the hard drive of the computer, if it can't find it it goes looking for the location it is stored on our server.

Private Sub Command140_Click()

On Error GoTo line1
FollowHyperlink "c:\natcoa\databaseguide.pdf"

GoTo line2
line1:

If Msgbox("Oops, 'databaseguide.pdf' has to be in 'c:/natcoa'. I can't locate it. Would you like to load it off our server instead?", vbYesNo, "Archive") = vbYes Then
DoCmd.SetWarnings False


FollowHyperlink "DoCmd.SetWarnings True
Else
End If

line2:

End Sub

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
Um, wrong forum/thread, avayaman? What does this post have to do with anything in this thread?
 
Nevermind. I see it now... [blush]

It's a case in point of how you accomplished what the OP mentioned. I got extra suspicious when you linked to a file on a thread that hasn't been active for a couple of weeks, now.
 
just going through thraads & noticed it.

Paul Beddows

Consulting, Avaya/EAS implementation, Training
Vancouver, Canada
E-mail paul at natcoa.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top