Welke ODBC driver gebruik ik?

ODBC wordt gebruikt om gegevens uit een database naar Excel te halen. ODBC staat voor Open Database Connectivity. Kun je verder vergeten. Om te weten of het stuurprogramma (de driver) geïnstalleerd is kun je onderstaande functie gebruiken

Public Function Get_Driver() As String
    Const HKEY_LOCAL_MACHINE = &H80000002
    Dim l_Registry As Object
    Dim l_RegStr As Variant
    Dim l_RegArr As Variant
    Dim l_RegValue As Variant

    Get_Driver = ""
    Set l_Registry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    l_Registry.enumvalues HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers", l_RegStr, l_RegArr

    For Each l_RegValue In l_RegStr
        If InStr(1, l_RegValue, "MySQL ODBC", vbTextCompare) > 0 Then
            Get_Driver = l_RegValue
            Exit For
        End If
    Next
    Set l_Registry = Nothing
End Function

Als je alle stuurprogramma’s op je computer wil tonen gebruik je onderstaande code:

Public Function Alle_ODBC_Stuurprogramma_Tonen(strComputerNaam)
Const HKEY_LOCAL_MACHINE = &H80000002
'*************************************************************************
'Naam:      Alle_ODBC_Stuurprogramma_Tonen
'Gemaakt:   07/08/2011
'Auteur:    Dennis Hemken
'Doel:      Geeft een lijst van alle geïnstalleerde stuurprogramma's
'           in een nieuw excel document
'*************************************************************************
Dim objRegistry
Dim strRegPath
Dim strAODBCDriverNames
Dim strAValueTypes
Dim strODBCDriverName
Dim strValue
Dim objExcel
Dim objRange
Dim lngRow
Dim i
 
    Set objExcel = CreateObject("Excel.Application")
  
    objExcel.Visible = True
    objExcel.Workbooks.Add
    lngRow = 1
    objExcel.Cells(lngRow, 1).Value = "Driver Name"
    objExcel.Cells(lngRow, 2).Value = "Value"
     
    objExcel.Cells(lngRow, 1).Font.Bold = True
    objExcel.Cells(lngRow, 2).Font.Bold = True
 
    strRegPath = "SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers"
     
    Set objRegistry = GetObject("winmgmts:\\" & _
    strComputerNaam & "\root\default:StdRegProv")
     
    objRegistry.EnumValues HKEY_LOCAL_MACHINE, _
    strRegPath, strAODBCDriverNames, strAValueTypes
 
    For i = 0 To UBound(strAODBCDriverNames)
        lngRow = lngRow + 1
         
        strODBCDriverName = strAODBCDriverNames(i)
        objRegistry.GetStringValue HKEY_LOCAL_MACHINE, _
        strRegPath, strODBCDriverName, strValue
        objExcel.Cells(lngRow, 1).Value = strODBCDriverName
        objExcel.Cells(lngRow, 2).Value = strValue
    Next
     
    Set objRange = objExcel.Range("A1")
    objRange.Activate
    Set objRange = objExcel.ActiveCell.EntireColumn
    objRange.Columns.AutoFit
    Set objRange = objExcel.Range("B1")
    objRange.Activate
    Set objRange = objExcel.ActiveCell.EntireColumn
    objRange.Columns.AutoFit
End Function

Resultaat:

Leave a Reply

Your email address will not be published. Required fields are marked *