# determining installed mdac version



## jjm2958 (Aug 26, 2004)

Anyone know a way to query the local system and return what version of mdac a machine has installed through vba?  I have an excel application that works great but will fail if the mdac version is too old - rather than have the customer's call me with their errors, I'd like to have a routine which would query the mdac version and if it's lower than a certain value, pop up a message box when they open the application.

Thanks for any help!
Jared


----------



## Greg Truby (Aug 26, 2004)

Um, I haven't a clue as to what "mdac" might mean here.  But (a) you can hit registry settings with VBA and (b) you can use a reference object to check on a reference's version number.  

If either of these ideas would help here, post back and let us know.  (Or perhaps someone else who does know what "mdac" means will stop by and know the answer to this straight away.)


----------



## jjm2958 (Aug 26, 2004)

Greg Truby said:
			
		

> Um, I haven't a clue as to what "mdac" might mean here.



MDAC is Microsoft Data Access Components 

Link is here...
http://www.microsoft.com/downloads/...e3-c795-4b7d-b037-185d0506396c&displaylang=en


----------



## Seti (Aug 26, 2004)

There is a component checker available from MS that may be a place to start.  Not sure if you could integrate it with VBA or not though.

http://www.microsoft.com/downloads/...f6-4a21-4b43-bf53-14332ef092c9&displaylang=en


----------



## jjm2958 (Aug 26, 2004)

I was able to find the registry key and use some code from another question on here and I think I got it to work.

Thanks all!


----------



## XL-Dennis (Aug 26, 2004)

Hi all,



> and I think I got it to work.



That is subject to what You more precisely mean with "got it to work" 

This is not an easy task so make sure You take part of the following KB-article:

http://support.microsoft.com/default.aspx?scid=kb;en-us;301202

It would be highly appreciated if You could show the code in use for the board.


----------



## Mudface (Aug 26, 2004)

I agree with Dennis- can you post your solution up, please?


----------



## Guest (Aug 26, 2004)

I've looked at this issue before and got no where !

I had a MS Word document which I was distributing around my company to a subset of PC. Some had MDAC 2.7, other 2.6 others 2.5 some even lower. The document had the MDAC 2.7 checked in the refrences section as this is what I had on my PC when I built it.

Problem is we had to send instructions out to everyone to check the references section in the VB and if MISSING appeared next to a ticked component ..... well, you can see my point, it got messy.

It would be more useful to be able to check and correct the references section appropriately. 

You could even look in the references section to find the most up to date version.

Chris


----------



## jjm2958 (Aug 27, 2004)

Well, here's what I used and from initial tests on other machines it's good enough for what I want.

I found the following code from another message on here, but now can't seem to find it again so I can't give proper credit - only to say that I didn't write it 


```
' 32-bit declarations
Private Declare Function RegOpenKeyA Lib "ADVAPI32.DLL" _
    (ByVal hKey As Long, ByVal sSubKey As String, _
    ByRef hkeyResult As Long) As Long

Private Declare Function RegCloseKey Lib "ADVAPI32.DLL" _
    (ByVal hKey As Long) As Long

Private Declare Function RegSetValueExA Lib "ADVAPI32.DLL" _
    (ByVal hKey As Long, ByVal sValueName As String, _
    ByVal dwReserved As Long, ByVal dwType As Long, _
    ByVal sValue As String, ByVal dwSize As Long) As Long

Private Declare Function RegCreateKeyA Lib "ADVAPI32.DLL" _
    (ByVal hKey As Long, ByVal sSubKey As String, _
    ByRef hkeyResult As Long) As Long

Private 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

Public Function GetRegistry(Key, Path, ByVal ValueName As String)
'  Reads a value from the Windows Registry

    Dim hKey As Long
    Dim lValueType As Long
    Dim sResult As String
    Dim lResultLen As Long
    Dim ResultLen As Long
    Dim x, TheKey As Long

    TheKey = -99
    Select Case UCase(Key)
        Case "HKEY_CLASSES_ROOT": TheKey = &H80000000
        Case "HKEY_CURRENT_USER": TheKey = &H80000001
        Case "HKEY_LOCAL_MACHINE": TheKey = &H80000002
        Case "HKEY_USERS": TheKey = &H80000003
        Case "HKEY_CURRENT_CONFIG": TheKey = &H80000004
        Case "HKEY_DYN_DATA": TheKey = &H80000005
    End Select
    
'   Exit if key is not found
    If TheKey = -99 Then
        GetRegistry = "Not Found"
        Exit Function
    End If

    If RegOpenKeyA(TheKey, Path, hKey) <> 0 Then _
        x = RegCreateKeyA(TheKey, Path, hKey)
    
    sResult = Space(100)
    lResultLen = 100
    
    x = RegQueryValueExA(hKey, ValueName, 0, lValueType, _
    sResult, lResultLen)
        
    Select Case x
        Case 0: GetRegistry = Left(sResult, lResultLen - 1)
        Case Else: GetRegistry = "Not Found"
    End Select
    
    RegCloseKey hKey
End Function
```

That's the function that will query the registry and return the value or "Not Found"

Then, I found on Microsoft's site the registry value that stores the MDAC version and made the call like this:


```
version = ModuleRegistry.GetRegistry("HKEY_LOCAL_MACHINE", "Software\Microsoft\DataAccess", "FullInstallVer")
    
    If ((Left(version, 3) <> "2.8") And (version <> "Not Found")) Then
	MsgBox "Your MDAC Version needs to be updated"
    ElseIf (version = "Not Found") Then
	MsgBox "I can't seem to find any installed version of MDAC on your machine"
    Else
        MDACVersion = "GOOD: Your MDAC version is greater than or equal to 2.8"
    End If
```

Again, not the most clean way probably but seems to work for me.

Jared


----------

