Results 1 to 3 of 3

Thread: Opening a PDF

  1. #1
    Join Date
    May 2004

    Unanswered: Opening a PDF


    I'm trying to open a .PDF from Acces using VBA. I have the following code attached to a command buttom :

    Private Sub Acrobat_test_Click()
    On Error GoTo Err_Acrobat_test_Click

    Dim stAppName As String

    stAppName = "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe D:\WINTERTHUR\PFP\PFP Tool\NL\test.pdf"
    Call Shell(stAppName, 1)

    Exit Sub

    MsgBox Err.Description
    Resume Exit_Acrobat_test_Click

    End Sub

    When clicking the CB, Acrobat opens, but gives the following remarks :
    "There was an error opening this document. The file does not exists."
    "There was an error opening this document. The path does not exists."

    Can anyone help me find and solve the problem...??


  2. #2
    Join Date
    Apr 2004
    Maybe you should try putting the app name and the doc name in 2 different strings.

  3. #3
    Join Date
    Nov 2003
    You will have better success if your paths are in Short name format rather than in Windows Long name format (Joliet - probably spelled wrong).

    Create a New database Code Module and name it GetShortLongFilenames. Place Copy and paste the following code into it (we are going to use Windows API calls to change your paths to Short name format):

    Option Compare Database
    Option Explicit
    'The functions fGetShortName and fGetLongName will return
    'the appropriate Short or Long filename.
    Private Const MAX_PATH& = 260
    Private Const INVALID_HANDLE_VALUE = -1
    	dwLowDateTime As Long
    	dwHighDateTime As Long
    End Type
    Type WIN32_FIND_DATA ' 318 Bytes
    	dwFileAttributes As Long
    	ftCreationTime As FILETIME
    	ftLastAccessTime As FILETIME
    	ftLastWriteTime As FILETIME
    	nFileSizeHigh As Long
    	nFileSizeLow As Long
    	dwReserved¯ As Long
    	dwReserved1 As Long
    	cFileName As String * MAX_PATH
    	cAlternate As String * 14
    End Type
    Private Declare Function apiFindFirstFile Lib "kernel32" _
    	Alias "FindFirstFileA" _
    	(ByVal lpFileName As String, _
    	lpFindFileData As WIN32_FIND_DATA) _
    	As Long
    Private Declare Function apiFindClose Lib "kernel32" _
    	Alias "FindClose" _
    	(ByVal hFindFile As Long) _
    	As Long
    Private Declare Function apiGetShortPathName Lib "kernel32" _
    	Alias "GetShortPathNameA" _
    	(ByVal lpszLongPath As String, _
    	ByVal lpszShortPath As String, _
    	ByVal cchBuffer As Long) _
    	As Long
    Public Function fGetShortName(ByVal stLongPath As String) As String
    '[opposite of fGetLongName()]
    'Usage Examples:
    '?fGetShortName("D:\Internet Explorer 5.0 Setup\This folder is safe to delete.txt")
    	Dim stShortPath As String
    	Dim lngBuffer As Long, lngRet As Long
    	stShortPath = String$(MAX_PATH, 0)
    	lngBuffer = Len(stShortPath)
    	lngRet = apiGetShortPathName(stLongPath, stShortPath, lngBuffer)
    	fGetShortName = Left(stShortPath, lngRet)
    End Function
    Public Function fGetLongName(ByVal strFileName As String) As String
    'Usage Examples:
    'D:\Internet Explorer 5.0 Setup\This folder is safe to delete.txt
    'C:\Program Files\Microsoft Office\Office\Samples\Solutions.mdb
    'C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb
    	Dim lpFindFileData As WIN32_FIND_DATA
    	Dim strPath As String, lngRet As Long
    	Dim strFile As String, lngX As Long, lngY As Long
    	Dim strTmp As String
    	strTmp = ""
    	Do While Not lngRet = INVALID_HANDLE_VALUE
    		lngRet = apiFindFirstFile(strFileName, lpFindFileData)
    		strFile = Left$(lpFindFileData.cFileName, _
    					InStr(lpFindFileData.cFileName, _
    					vbNullChar) - 1)
    		If Len(strFileName) > 2 Then
    			strTmp = strFile & "\" & strTmp
    			strFileName = fParseDir(strFileName)
    			strTmp = strFileName & "\" & strTmp
    			Exit Do
    		End If
    	fGetLongName = Left$(strTmp, Len(strTmp) - 1)
    	lngY = apiFindClose(lngRet)
    End Function
    Private Function fParseDir(strInFile As String) As String
    	Dim intLen As Long, boolFound As Boolean
    	Dim i As Integer, f As String, strDir As String
    	intLen = Len(strInFile)
    	If intLen > 0 Then
    		boolFound = False
    		For i = intLen To 1 Step -1
    			If Mid$(strInFile, i, 1) = "\" Then
    				f = Mid$(strInFile, i + 1)
    				strDir = Left$(strInFile, i - 1)
    				boolFound = True
    				Exit For
    			End If
    		Next i
    		End If
    	If boolFound Then
    		fParseDir = strDir
    		fParseDir = strInFile
    	End If
    End Function
    Now...Set your stAppName string variable to read as:

    stAppName = fGetShortName("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe") & _
    " " & fGetShortName("D:\WINTERTHUR\PFP\PFP Tool\NL\test.pdf")
    or you might just get away with:

    stAppName = "C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe " & _
    fGetShortName("D:\WINTERTHUR\PFP\PFP Tool\NL\test.pdf")
    Hope this helps......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts