Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2004
    Location
    Kampala, Uganda
    Posts
    32

    Question Unanswered: Opening Acrobat reader from Access

    I'm trying to open Adobe Acrobat Reader from access to view a file that I've programatically just exported to it.

    This is the code I'm using;

    strAppName = "acrord32.exe " & strExportedFile
    Call Shell(strAppName, 1)

    The error I get is; 55 file not found

    All of the follwoing work ok;
    strAppName = "notepad.exe " & strExportedFile
    strAppName = "excel.exe " & strExportedFile
    strAppName = "explorer.exe " & strExportedFile

    If I enter acrord32.exe from the Start/Run window (I'm using XP Professional) then acrobat reader starts OK.

    I dont want to have to hardcode in the path to acrobat reader because the app is used on different computers.

    Any ideas?

    Is there a way I can get the path to acrobat reader from the registry? (this scares me!)

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Try to write the full path where your Acrobat is installed

  3. #3
    Join Date
    Apr 2004
    Location
    Kampala, Uganda
    Posts
    32
    If I write the full path it works OK. But I cant assume the path will be the same on every computer the app runs on. Thats why I ask if its possible to get the path from the registry or some other easy way of finding it quickly.

  4. #4
    Join Date
    Nov 2003
    Location
    Romania
    Posts
    70
    Read in Registri this key:

    "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Cur rentVersion\App Paths\AcroRd32.exe"

  5. #5
    Join Date
    Apr 2004
    Location
    Kampala, Uganda
    Posts
    32
    How do I read from the registry correctly? Can you give me an example.

    I've tried using the GetSetting command but it always returns an empty string. I've checked my registry and acrobat reader is exactly where its supposed to be.

  6. #6
    Join Date
    Nov 2003
    Location
    Romania
    Posts
    70
    0. Read Registri: AcrobatPath = CitesteValoareREG(Transforma_HKEY_IN_LONG("HKEY_LO CAL_MACHINE"), "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\AcroRd32.exe", "")

    1. Check registri: If Exista_Registru(Transforma_HKEY_IN_LONG("HKEY_LOCA L_MACHINE"), "Software\SOVIASERV\EU") = False Then

    2. Create registri: If CreeazaREG("Software\SOVIASERV\EU", Transforma_HKEY_IN_LONG("HKEY_LOCAL_MACHINE")) = False Then

    3. Write new value: SeteazaValoareREG Transforma_HKEY_IN_LONG("HKEY_LOCAL_MACHINE"), "Software\SOVIASERV\EU", "Nume", "Streian Ovidiu", REG_SZ


    Public Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
    End Type


    Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
    (LpVersionInformation As OSVERSIONINFO) As Long

    Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

    Global Const REG_SZ As Long = 1
    Global Const REG_DWORD As Long = 4
    Global Const REG_EXPAND_SZ As Long = 2

    Global Const ERROR_NONE = 0
    Global Const ERROR_BADDB = 1
    Global Const ERROR_BADKEY = 2
    Global Const ERROR_CANTOPEN = 3
    Global Const ERROR_CANTREAD = 4
    Global Const ERROR_CANTWRITE = 5
    Global Const ERROR_OUTOFMEMORY = 6
    Global Const ERROR_INVALID_PARAMETER = 7
    Global Const ERROR_ACCESS_DENIED = 8
    Global Const ERROR_INVALID_PARAMETERS = 87
    Global Const ERROR_NO_MORE_ITEMS = 259

    Global Const KEY_ALL_ACCESS = &H3F

    Global Const REG_OPTION_NON_VOLATILE = 0


    Declare Function RegCloseKey Lib "advapi32.dll" _
    (ByVal hKey As Long) As Long

    Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
    "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
    ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions _
    As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes _
    As Long, phkResult As Long, lpdwDisposition As Long) As Long

    Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
    "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
    ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As _
    Long) As Long

    Declare Function RegQueryValueExString Lib "advapi32.dll" Alias _
    "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
    String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
    As String, lpcbData As Long) As Long

    Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias _
    "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
    String, ByVal lpReserved As Long, lpType As Long, lpData As _
    Long, lpcbData As Long) As Long

    Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
    "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
    String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
    As Long, lpcbData As Long) As Long

    Declare Function RegSetValueExString Lib "advapi32.dll" Alias _
    "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
    ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As _
    String, ByVal cbData As Long) As Long

    Declare Function RegSetValueExLong Lib "advapi32.dll" Alias _
    "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
    ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, _
    ByVal cbData As Long) As Long

    Function Transforma_HKEY_IN_LONG(hKey As String) As Long

    Const HKEY_CLASSES_ROOT = &H80000000
    Const HKEY_CURRENT_USER = &H80000001
    Const HKEY_LOCAL_MACHINE = &H80000002
    Const HKEY_USERS = &H80000003
    Const HKEY_PERFORMANCE_DATA = &H80000004
    Const HKEY_CURRENT_CONFIG = &H80000005
    Const HKEY_DYN_DATA = &H80000006

    Select Case hKey
    Case "HKEY_CLASSES_ROOT"
    Transforma_HKEY_IN_LONG = HKEY_CLASSES_ROOT
    Case "HKEY_CURRENT_USER"
    Transforma_HKEY_IN_LONG = HKEY_CURRENT_USER
    Case "HKEY_LOCAL_MACHINE"
    Transforma_HKEY_IN_LONG = HKEY_LOCAL_MACHINE
    Case "HKEY_USERS"
    Transforma_HKEY_IN_LONG = HKEY_USERS
    Case "HKEY_PERFORMANCE_DATA"
    Transforma_HKEY_IN_LONG = HKEY_PERFORMANCE_DATA
    Case "HKEY_CURRENT_CONFIG"
    Transforma_HKEY_IN_LONG = HKEY_CURRENT_CONFIG
    Case "HKEY_DYN_DATA"
    Transforma_HKEY_IN_LONG = HKEY_DYN_DATA
    End Select

    End Function
    Public Function Exista_Registru(LngHKEYPredefinit As Long, sKeyName As String) As Boolean

    '************************************************* ***************************
    '* RETURNEAZA FALSE DACA REGISTRU RESPECTIV NU EXISTA
    '* RETURNEAZA TRUE DACA EXISTA REGISTRUL
    '* Cum se utilizeaza :
    '* Exista_registru("HKEY_LOCAL_MACHINE" , "Software\MyKey1\MyKey2\")
    '************************************************* ****************************

    Dim lRetVal As Long ' valoare returnata
    Dim hKey As Long 'handle of open key

    'open the specified key
    lRetVal = RegOpenKeyEx(LngHKEYPredefinit, sKeyName, 0, _
    KEY_ALL_ACCESS, hKey)

    If lRetVal <> 0 Then
    Exista_Registru = False
    Else
    Exista_Registru = True
    End If

    End Function
    ' CREAZA O NOUA CHEIE IN REGISTRU
    Public Function CreeazaREG(strNewKeyName As String, LngHKEYPredefinit As Long) As Long
    Dim hNewKey As Long 'handle to the new key
    Dim lRetVal As Long 'result of the RegCreateKeyEx function

    lRetVal = RegCreateKeyEx(LngHKEYPredefinit, strNewKeyName, 0&, _
    vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, _
    0&, hNewKey, lRetVal)

    CreeazaREG = lRetVal

    RegCloseKey (hNewKey)

    End Function
    ' VERIFICA CE TIP DATE VA FI SETAT PTR CHEIE
    Public Function SetValueEx(ByVal hKey As Long, sValueName As String, _
    lType As Long, vValue As Variant) As Long

    Dim lValue As Long
    Dim sValue As String

    Select Case lType
    Case REG_SZ
    sValue = vValue & Chr$(0)
    SetValueEx = RegSetValueExString(hKey, sValueName, 0&, _
    lType, sValue, Len(sValue))
    Case REG_DWORD
    lValue = vValue
    SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, _
    lType, lValue, 4)

    End Select
    End Function
    ' SETEAZA VALOAREA CHEII
    Public Sub SeteazaValoareREG(LngHKEYPredefinit As Long, sKeyName As String, sValueName As String, _
    vValueSetting As Variant, lValueType As Long)
    Dim lRetVal As Long 'result of the SetValueEx function
    Dim hKey As Long 'handle of open key

    'Deschid cheia din registrul respectiv
    ' Se returneaza zero daca exista
    lRetVal = RegOpenKeyEx(LngHKEYPredefinit, sKeyName, 0, _
    KEY_ALL_ACCESS, hKey)
    ' Setez valoare cheia respective
    ' functia SetValueEx este o functie care foloseste functia API
    ' RegSetValueEx (Long sau String in functie de lValueType = REG_SZ sau REG_DWORD)
    lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting)
    ' Inchid registru si cheia
    RegCloseKey (hKey)
    End Sub
    ' DETERMINA CE DIT DE DATE VA FI CITIT DIN CHEIE
    Public Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As _
    String, vValue As Variant) As Long
    'Determina tipul de date ce va fi citit
    ' Nu suporta decit string sau numeric
    Dim cch As Long
    Dim lrc As Long
    Dim lType As Long
    Dim lValue As Long
    Dim sValue As String

    On Error GoTo QueryValueExError

    ' Determine the size and type of data to be read
    lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
    If lrc <> ERROR_NONE Then Error 5

    Select Case lType
    ' For strings
    Case REG_SZ:
    sValue = String(cch, 0)
    lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, _
    sValue, cch)
    If lrc = ERROR_NONE Then
    vValue = Left$(sValue, cch - 1)
    Else
    vValue = Empty
    End If
    ' For DWORDS
    Case REG_DWORD:
    lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, _
    lValue, cch)
    If lrc = ERROR_NONE Then vValue = lValue
    Case Else
    'all other data types not supported
    lrc = -1
    End Select

    QueryValueExExit:
    QueryValueEx = lrc
    Exit Function
    QueryValueExError:
    Resume QueryValueExExit
    End Function

    Public Function CitesteValoareREG(LngHKEYPredefinit As Long, sKeyName As String, sValueName As String) As Variant
    'Returneaza EMPTY in cazul in care nu exista NUMELE CHEII din registru
    'Atentie nu calea pina la registru si CHEIA
    Dim lRetVal As Long 'result of the API functions
    Dim hKey As Long 'handle of opened key
    Dim vValue As Variant 'setting of queried value

    lRetVal = RegOpenKeyEx(LngHKEYPredefinit, sKeyName, 0, _
    KEY_ALL_ACCESS, hKey)
    lRetVal = QueryValueEx(hKey, sValueName, vValue)

    CitesteValoareREG = vValue

    RegCloseKey (hKey)
    End Function

Posting Permissions

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