Problem opening PDF files as a link

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neiluk69
    New Member
    • Sep 2007
    • 4

    Problem opening PDF files as a link

    I have created a form with a hyperlink which opens a PDF file.

    However when you click the link the file opens briefly and shuts down automatically, I have tried opening diffetrent file type and they work fine it is just the PDF that messes up.

    For clarification if I open the PDF from explorer it works fine and I have tried several files.

    Any suggestions.

    Neil
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    You have inadvertently posted your question in the Articles section rather than in the Forum section of our site, so I have moved it across to the Forum for you.

    Welcome to TheScripts!

    Linq ;0)>

    Comment

    • puppydogbuddy
      Recognized Expert Top Contributor
      • May 2007
      • 1923

      #3
      Originally posted by neiluk69
      I have created a form with a hyperlink which opens a PDF file.

      However when you click the link the file opens briefly and shuts down automatically, I have tried opening diffetrent file type and they work fine it is just the PDF that messes up.

      For clarification if I open the PDF from explorer it works fine and I have tried several files.

      Any suggestions.

      Neil
      Neil,

      Try using the ShellExecute method. It does not have the limitations that the Shell() function and Application.Fol lowHyperLink method do.

      The following example uses ShellExecute on a button click event:
      Code:
      Dim strPdfWriterPath As String
      Dim strFilePath As String
      
      'Open File
      'strPdfWriterPath is the path to the application object
      'strFilePath is the path to the file you want to open
      
      strPdfWriterPath = "C:\Program Files\Adobe\Acrobat 5.0\Acrobat\Acrobat.exe"
      strFilePath = Me.FilePath
      
      Call Shell(strPdfWriterPath & " " & strFilePath, vbMaximizedFocus)

      Comment

      • neiluk69
        New Member
        • Sep 2007
        • 4

        #4
        many thanks puppydog, it worked

        Comment

        • zigzag
          New Member
          • Aug 2007
          • 2

          #5
          Neil,

          Just to add, the problem you were seeing originaly is due to an issue with Acrobat reader. If you check you will probably find that it is version 7.0.0.
          If you get the latest version it will cure the problem.

          Garry

          Comment

          • Kevin Wilcox
            New Member
            • Sep 2007
            • 68

            #6
            Originally posted by zigzag
            Neil,

            Just to add, the problem you were seeing originaly is due to an issue with Acrobat reader. If you check you will probably find that it is version 7.0.0.
            If you get the latest version it will cure the problem.

            Garry
            Just to add to this further, I had the same issue; this only occurred on machines that had both Adobe Acrobat and Adobe Reader installed, fairly common in our setup. I had to explicitly open the doc in reader. here's a section of the code I used in case it's of use to others, I know it took me days to find the answer on the web!

            Code:
                fCloseApp ("AdobeAcrobat")
                Set fs = CreateObject("Scripting.FileSystemObject")
                MyCaseID = Me.CaseID
                
                'prints case documents where checkboxes are ticked
                If Me.PrintDocs = -1 Then
                    Set MyControl = Forms!frmPatients.Form!sfrmCases.Form!sfrmDocuments
                    MyControl.SetFocus
                    Set ObjRecordSet = MyControl.Form.RecordsetClone
                    ObjRecordSet.MoveFirst
                    Do Until ObjRecordSet.EOF
                        If ObjRecordSet.Print = -1 Then
                            MySourceDir = DocPathWay
                            MyFileName = ObjRecordSet.FileName
                            StrOutputFile = MySourceDir & MyFileName
                            strAcroPath = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"
                                If fs.FileExists(StrOutputFile) = True Then
                                    strAcroPath = strAcroPath & " /t " & StrOutputFile
                                    dwReturn = Shell(strAcroPath, vbMinimizedNoFocus)
                                    DoCmd.SetWarnings False
                                    MySQL = "INSERT INTO tblPrintHistory (EventType, UserID, CaseID, Document, PrintDate) " & _
                                    "SELECT 1 as EventType, """ & fosEmpID & """ as UserID, """ & MyCaseID & """ as CaseID, " & _
                                    """" & stDocName & """ as document, Now() as PrintDate;"
                                    DoCmd.RunSQL MySQL
                                    DoCmd.SetWarnings True
                    
                                Else
                                    MsgBox StrOutputFile & " does not exist"
                                End If
                        End If
                    ObjRecordSet.MoveNext
                    Loop
                End If

            Comment

            Working...