determining installed mdac version

jjm2958

New Member
Joined
Aug 20, 2004
Messages
12
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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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.)
 
Upvote 0
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!
 
Upvote 0
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
 
Upvote 0
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 :)

Code:
' 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:

Code:
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
 
Upvote 0

Forum statistics

Threads
1,216,500
Messages
6,131,016
Members
449,615
Latest member
Nic0la

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top