Solved

Detect Version of MSAccess

Posted on 2001-06-22
8
208 Views
Last Modified: 2010-05-02
I am using a VB prog to open an access database.  It will open a A2k database if A2k is installed, otherwise it will open A97 version.

I simply need to determine if A2k is installed on the machine, without opening Access to do it.

Thanks,

JS
0
Comment
Question by:jdlsmith
  • 5
  • 3
8 Comments
 
LVL 3

Expert Comment

by:jrspano
ID: 6219455
why not find the file msaccess.exe and then get the version of it 2000 is 9.0.0.buildversion

i think 97 is version 8.0.0
0
 
LVL 1

Author Comment

by:jdlsmith
ID: 6219463
How do you get the version?
0
 
LVL 1

Author Comment

by:jdlsmith
ID: 6219475
How do you get the version?
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6219478
here is code from freevbcode.com to get the paths to office products

Option Explicit

Private 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

Private Declare Function RegQueryValueEx 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
                                                                                                 
Private Declare Function RegCloseKey Lib "advapi32.dll" _
   (ByVal hKey As Long) As Long

Private Const REG_SZ As Long = 1
Private Const KEY_ALL_ACCESS = &H3F
Private Const HKEY_LOCAL_MACHINE = &H80000002

Code:


'*****************************************************
'These functions return the path to the specified office
'application or a 0-length string if the application does not
'exist on the machine.  This is one good way to check whether a
'specific office application is present before trying to run
'automation code for that application
'*****************************************************
Public Function GetWordPath() As String
    GetWordPath = GetOfficeAppPath("Word.Application")
End Function

Public Function GetExcelPath() As String
    GetExcelPath = GetOfficeAppPath("Excel.Application")
End Function

Public Function GetAccessPath() As String
    GetAccessPath = GetOfficeAppPath("Access.Application")
End Function

Public Function GetOutlookPath() As String
    GetOutlookPath = GetOfficeAppPath("Outlook.Application")
End Function

Public Function GetPowerPointPath() As String
    GetPowerPointPath = _
       GetOfficeAppPath("PowerPoint.Application")
End Function

Public Function GetFrontPagePath() As String
    GetFrontPagePath = GetOfficeAppPath("FrontPage.Application")
End Function

Private Function GetOfficeAppPath(ByVal ProgID As String) _
   As String

Dim lKey As Long
Dim lRet As Long
Dim sClassID As String
Dim sAns As String
Dim lngBuffer As Long
Dim lPos As Long

   'GetClassID
   lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
          "Software\Classes\" & ProgID & "\CLSID", 0&, _
           KEY_ALL_ACCESS, lKey)
   If lRet = 0 Then
 
      lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, "", lngBuffer)
      sClassID = Space(lngBuffer)
      lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, sClassID, _
          lngBuffer)

      'drop null-terminator
      sClassID = Left(sClassID, lngBuffer - 1)
      RegCloseKey lKey
   End If
   
   
   'Get AppPath
    lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
        "Software\Classes\CLSID\" & sClassID & _
        "\LocalServer32", 0&, KEY_ALL_ACCESS, lKey)
 
  If lRet = 0 Then
      lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, "", lngBuffer)
      sAns = Space(lngBuffer)
      lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, sAns, _
        lngBuffer)
      sAns = Left(sAns, lngBuffer - 1)
     
      RegCloseKey lKey
   End If
   
   
    'Sometimes the registry will return a switch
       'beginning with "/" e.g., "/automation"
   
    lPos = InStr(sAns, "/")
        If lPos > 0 Then
            sAns = Trim(Left(sAns, lPos - 1))
        End If
   
    GetOfficeAppPath = sAns
   
End Function
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 3

Accepted Solution

by:
jrspano earned 300 total points
ID: 6219493
once you have the path then use this


set a refference to ms scripting runtime

Dim f As New FileSystemObject
Dim s As String

s = f.GetFileVersion(path and filename)
this will give you the version
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6219521
here is the example put together

make a project with 1 form and add a command button with name command1 cut and paste code below


Option Explicit
Private 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

Private Declare Function RegQueryValueEx 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
                                                                                                 
Private Declare Function RegCloseKey Lib "advapi32.dll" _
  (ByVal hKey As Long) As Long

Private Const REG_SZ As Long = 1
Private Const KEY_ALL_ACCESS = &H3F
Private Const HKEY_LOCAL_MACHINE = &H80000002



'*****************************************************
'These functions return the path to the specified office
'application or a 0-length string if the application does not
'exist on the machine.  This is one good way to check whether a
'specific office application is present before trying to run
'automation code for that application
'*****************************************************
Public Function GetWordPath() As String
   GetWordPath = GetOfficeAppPath("Word.Application")
End Function

Public Function GetExcelPath() As String
   GetExcelPath = GetOfficeAppPath("Excel.Application")
End Function

Public Function GetAccessPath() As String
   GetAccessPath = GetOfficeAppPath("Access.Application")
End Function

Public Function GetOutlookPath() As String
   GetOutlookPath = GetOfficeAppPath("Outlook.Application")
End Function

Public Function GetPowerPointPath() As String
   GetPowerPointPath = _
      GetOfficeAppPath("PowerPoint.Application")
End Function

Public Function GetFrontPagePath() As String
   GetFrontPagePath = GetOfficeAppPath("FrontPage.Application")
End Function

Private Function GetOfficeAppPath(ByVal ProgID As String) _
  As String

Dim lKey As Long
Dim lRet As Long
Dim sClassID As String
Dim sAns As String
Dim lngBuffer As Long
Dim lPos As Long

  'GetClassID
  lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
         "Software\Classes\" & ProgID & "\CLSID", 0&, _
          KEY_ALL_ACCESS, lKey)
  If lRet = 0 Then

     lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, "", lngBuffer)
     sClassID = Space(lngBuffer)
     lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, sClassID, _
         lngBuffer)

     'drop null-terminator
     sClassID = Left(sClassID, lngBuffer - 1)
     RegCloseKey lKey
  End If
 
   
  'Get AppPath
   lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
       "Software\Classes\CLSID\" & sClassID & _
       "\LocalServer32", 0&, KEY_ALL_ACCESS, lKey)

 If lRet = 0 Then
     lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, "", lngBuffer)
     sAns = Space(lngBuffer)
     lRet = RegQueryValueEx(lKey, "", 0&, REG_SZ, sAns, _
       lngBuffer)
     sAns = Left(sAns, lngBuffer - 1)
     
     RegCloseKey lKey
  End If
   
   
   'Sometimes the registry will return a switch
      'beginning with "/" e.g., "/automation"
   
   lPos = InStr(sAns, "/")
       If lPos > 0 Then
           sAns = Trim(Left(sAns, lPos - 1))
       End If
   
   GetOfficeAppPath = sAns
   
End Function


Private Sub Command1_Click()

Dim s As String
Dim a As String
s = GetAccessPath

Dim f As New FileSystemObject

a = f.GetFileVersion(s)  'a has version here

if left$(a,1) = "9" then
  'access2000
endif


End Sub
0
 
LVL 1

Author Comment

by:jdlsmith
ID: 6219539
Perfect!  appreciate the other code too (i'll implement it later)

Thanks!

JS
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6219559
glad i could help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now