Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locating Office and Access Versions via the registry

Status
Not open for further replies.

sykola

Programmer
Nov 14, 2000
2
US
I have a VB application that uses an mdb file. However this app will only work with Access97 and up. I am trying to find the best way to test the Access version when you first run the app. I know that the HKLM/software/microsoft registry can ususaly have two different entries for Office (MS Office 97 Proffessional and Office) but which should I use? And will it account for a system with Access only without Office?
 
'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Insert this code to the module :

Public Const HKEY_CLASSES_ROOT = &H80000000
Declare Function RegOpenKey Lib "advapi32" Alias "RegOpenKeyA" (ByVal hKey _
As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" _
(ByVal hKey As Long, ByVal lpValueName As String, lpReserved As Long, lptype As _
Long, lpData As Any, lpcbData As Long) As Long
Declare Function RegCloseKey& Lib "advapi32" (ByVal hKey&)
Public Const REG_SZ = 1
Public Const REG_EXPAND_SZ = 2
Public Const ERROR_SUCCESS = 0

'Insert the following code to your form:

Public Function GetRegString(hKey As Long, _
strSubKey As String, strValueName As _
String) As String
Dim strSetting As String
Dim lngDataLen As Long
Dim lngRes As Long
If RegOpenKey(hKey, strSubKey, _
lngRes) = ERROR_SUCCESS Then
strSetting = Space(255)
lngDataLen = Len(strSetting)
If RegQueryValueEx(lngRes, _
strValueName, ByVal 0, _
REG_EXPAND_SZ, ByVal strSetting, _
lngDataLen) = ERROR_SUCCESS Then
If lngDataLen > 1 Then
GetRegString = Left(strSetting, lngDataLen - 1)
End If
End If

If RegCloseKey(lngRes) <> ERROR_SUCCESS Then
MsgBox &quot;RegCloseKey Failed: &quot; & _
strSubKey, vbCritical
End If
End If
End Function

Function FileExists(sFileName$) As Boolean
On Error Resume Next
FileExists = IIf(Dir(Trim(sFileName)) <> &quot;&quot;, _
True, False)
End Function

Public Function IsAppPresent(strSubKey$, _
strValueName$) As Boolean
IsAppPresent = CBool(Len(GetRegString(HKEY_CLASSES_ROOT, _
strSubKey, strValueName)))
End Function

Private Sub Form_Load()
MsgBox &quot;Access &quot; & _
IsAppPresent(&quot;Access.Database\CurVer&quot;, &quot;&quot;)
MsgBox &quot;Excel &quot; & _
IsAppPresent(&quot;Excel.Sheet\CurVer&quot;, &quot;&quot;)
MsgBox &quot;PowerPoint &quot; & _
IsAppPresent(&quot;PowerPoint.Slide\CurVer&quot;, &quot;&quot;)
MsgBox &quot;Word &quot; & _
IsAppPresent(&quot;Word.Document\CurVer&quot;, &quot;&quot;)
End Sub


Eric


Eric De Decker
vbg.be@vbgroup.nl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top