Check if Acrobat Reader is installed using VBA

Webbenstein

New member
Local time
Today, 09:54
Joined
Jan 7, 2007
Messages
8
Hi there,

Does anyone out there know how to write VBA code which checks if Adobe Acrobat is installed on the pc a db is running on?

The context of the problem is this: I am opening reports up as .pdf files automatically in code. If Acrobat isn't installed then I want to be able to open the reports normally in access. If acrobat is installed then the reports will open as .pdf files.

Many thanks for any help...
 
I "stole" below code to find if and where Oracle is installed. You can probably addapt it to find Adobe....

Code:
Option Compare Database
Option Explicit

'Module for reading registry keys
'2006-02-02
'Found on the internet http://www.ozgrid.com/forum/showthread.php?t=18108
'2006-02-02 EW changed to handle value type CZ (reading till null char)

Const MAX_STRING As Long = 128
Public Const REG_CZ = 1&
Public Const REG_BINARY = 3&
Public Const REG_DWORD = 4&
 
Declare Function RegOpenKeyA Lib "ADVAPI32.DLL" _
(ByVal hkey As Long, _
ByVal sKey As String, _
ByRef plKeyReturn As Long) As Long
 
Declare Function RegQueryValueExA Lib "ADVAPI32.DLL" _
(ByVal hkey As Long, _
ByVal sValueName As String, _
ByVal dwReserved As Long, _
ByRef lValueType As Long, _
ByVal sValue As String, _
ByRef lResultLen As Long) As Long
 
Declare Function RegCloseKey Lib "ADVAPI32.DLL" _
(ByVal hkey As Long) As Long
 
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
'
 
Sub ShowExcelProductID()
    'Example of calling the  function...
    MsgBox GetRegistryValue(HKEY_LOCAL_MACHINE, _
    "Software\Microsoft\Microsoft Excel 97\97.2.0.0717(1033)\Registration", "ProductID")
End Sub
 
Function GetRegistryValue(KEY As Long, SubKey As String, _
    ValueName As String) As String
    'Pass:
    '   (1) the KEY (e.g., HKEY_CLASSES_ROOT),
    '   (2) the SUBKEY (e.g., "Excel.Sheet.5"),
    '   (3) the value's name (e.g., "" [for default] Or "whatever")
     
     
    Dim Buffer As String * MAX_STRING, ReturnCode As Long
    Dim KeyHdlAddr As Long, ValueType As Long, ValueLen As Long
    Dim TempBuffer As String, Counter As Integer
    ValueLen = MAX_STRING
    ReturnCode = RegOpenKeyA(KEY, SubKey, KeyHdlAddr)
    If ReturnCode = 0 Then
        ReturnCode = RegQueryValueExA(KeyHdlAddr, ValueName, _
        0&, ValueType, Buffer, ValueLen)
        RegCloseKey KeyHdlAddr
        'If successful ValueType contains data type
        ' of value And ValueLen its length
        If ReturnCode = 0 Then
            Select Case ValueType
            Case REG_BINARY
                For Counter = 1 To ValueLen
                    TempBuffer = TempBuffer & _
                    Stretch(Hex(Asc(Mid(Buffer, Counter, 1)))) & " "
                Next
                GetRegistryValue = TempBuffer
            Case REG_DWORD
                TempBuffer = "0x"
                For Counter = 4 To 1 Step -1
                    TempBuffer = TempBuffer & _
                    Stretch(Hex(Asc(Mid(Buffer, Counter, 1))))
                Next
                GetRegistryValue = TempBuffer
            Case REG_CZ
                If InStr(1, Buffer, Chr(0)) > 0 Then
                    GetRegistryValue = Left(Buffer, InStr(1, Buffer, Chr(0)) - 1)
                Else
                    GetRegistryValue = ""
                End If
            Case Else
                GetRegistryValue = Buffer
            End Select
            Exit Function
        End If
    End If
    GetRegistryValue = "Error"
End Function
 
Function Stretch(ByteStr As String) As String
    If Len(ByteStr) = 1 Then ByteStr = "0" & ByteStr
    Stretch = ByteStr
End Function
 
Cool, thanks, I'll give it a bash...
 

Users who are viewing this thread

Back
Top Bottom