vba mysql odbc,使用VBA,找到Windows中安装的MySQL ODBC驱动程序的版本

Using Visual Basic for Applications, how can I find out which version of the MySQL ODBC driver is installed in Windows on a user's machine?

I have a Microsoft Access application that uses the MySQL ODBC driver to make a connection. The connection string looks like this:

ODBC;DATABASE=mydatabase;DRIVER={MySQL ODBC 3.51 Driver};

OPTION=3;PWD=password;PORT=3306;SERVER=server-db;UID=db-user;

This was working find until the IT manager installed version 5.1 of the MySQL ODBC driver on a user's PC, which broke my connection string.

If I knew the version of the driver installed on the user's Windows XP installation, I could insert that into the connection string at run-time. How can I find out which version of the MySQL ODBC driver is installed in Windows on a user's machine using VBA?

解决方案

You can find it in the registry under

HKEY_LOCAL_MACHINE\SOFTWARE\

ODBC\ODBCINST.INI\

ODBC Drivers\MySQL ODBC 3.51 Driver

HKEY_LOCAL_MACHINE\SOFTWARE\

ODBC\ODBCINST.INI\

ODBC Drivers\MySQL ODBC 5.1 Driver

Using the info found here, you can get at it using the below code (I tested it in Access 97)

Private Sub Command0_Click()

If RegKeyExists("HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\

ODBC Drivers\MySQL ODBC 3.51 Driver") Then

MsgBox "3.51"

ElseIf RegKeyExists("HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\

ODBC Drivers\MySQL ODBC 5.1 Driver") Then

MsgBox "5.1"

Else

MsgBox "None"

End If

End Sub

'returns True if the registry key i_RegKey was found

'and False if not

Function RegKeyExists(i_RegKey As String) As Boolean

Dim myWS As Object

On Error GoTo ErrorHandler

'access Windows scripting

Set myWS = CreateObject("WScript.Shell")

'try to read the registry key

myWS.RegRead i_RegKey

'key was found

RegKeyExists = True

Exit Function

ErrorHandler:

'key was not found

RegKeyExists = False

End Function

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值