Connecting Ms Access Db to Mysql through Vba

只谈情不闲聊 提交于 2021-02-20 03:40:23

问题


I have been trying to connect mysql database to ms Access but no result.I don't think personally I am using the DAo.Connection and the workspace properly. I keep on getting the 3001 connection error when I set mySqlCon. I guess my arguments are not properly set but I was following an example from here.

Function connectingMySql()
   Dim mySqlCon As Dao.Connection
   Dim wrkODBC As Workspace

   Set wrkODBC = CreateWorkspace("newODBCWorkspace", "admin", "", dbUseODBC)

   Set mySqlCon = wrkODBC.OpenConnection("connection1", , , "DRIVER={MYSQL ODBC 5.1 DRIVER};" _
   & "SERVER=testserver.com;port=3306;" _
   & "DATABASE=test;" _
   & "USER=root;" _
   & "PASSWORD=pass;" _
   & "Option=3;")
End Function

More infos:

  • Running Ms Access 2003

回答1:


This MSDN page says that using dbUseODBC will cause a runtime error.

ODBCDirect workspaces are not supported in Microsoft Access 2010. Setting the type argument to dbUseODBC will result in a run-time error. Use ADO if you want to access external data sources without using the Microsoft Access database engine.

Try Set wrkODBC = CreateWorkspace("newODBCWorkspace", "admin", "")




回答2:


After much struggle, I fixed it. Basically my arguments where wrong. Now I am getting a connection Error, which means the argument error has been fixed.

Function connectingMySql()
   Dim mySqlCon As Dao.Connection
   Dim wrkODBC As Workspace

   Set wrkODBC = CreateWorkspace("newODBCWorkspace", "admin", "", dbUseODBC)

   Set mySqlCon = wrkODBC.OpenConnection("DRIVER={MYSQL ODBC 5.1 DRIVER};" _
   & "SERVER=testserver.com;port=3306;" _
   & "DATABASE=test;" _
   & "USER=root;" _
   & "PASSWORD=pass;" _
   & "Option=3;")
End Function


来源:https://stackoverflow.com/questions/30650601/connecting-ms-access-db-to-mysql-through-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!