[英]MS Access : Macro Button to download Table from MySQL
I'm trying to create a button that connects to a MySQL DB and downloads tables (when clicked).我正在尝试创建一个连接到 MySQL 数据库并下载表的按钮(单击时)。 I created the following Macro :
我创建了以下宏:
Sub ADO_conn_Click()
Dim conn As New Connection
Dim rs As New Recordset
strcon = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=test1.server.net:63306" & _
"User Id=admin;Password=test"
conn.Open (strcon)
qry = "SELECT * FROM Employee"
rs.Open qry, conn, adOpenKeyset
rs.Close
conn.Close
End Sub
Source : http://www.learnexcelmacro.com/wp/2011/12/how-to-connect-to-access-database-excel-macro/ - i also did the prerequisites.来源: http : //www.learnexcelmacro.com/wp/2011/12/how-to-connect-to-access-database-excel-macro/ - 我也做了先决条件。 When I try to run the macro, I get the following error : "Compile Error - Invalid use of New Keyword" .
当我尝试运行宏时,出现以下错误:“编译错误 - 新关键字的使用无效”。 Any Ideas on what I'm doing wrong?
关于我做错了什么的任何想法? Thanks for your help.
谢谢你的帮助。
in strcon
between your second and third line there is no space.在第二行和第三行之间的
strcon
中没有空格。 Is the word 'user' meant to be apart of the data source as in... Source=test1.server.net:63306User
? 'user' 这个词是不是应该作为数据源的一部分,如...
Source=test1.server.net:63306User
?
I think you need a semicolon so try the following... I also think that you might have to declare strcon
as a string variable.我认为您需要一个分号,因此请尝试以下操作...我还认为您可能必须将
strcon
声明为字符串变量。
dim strcon as string
strcon = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=test1.server.net:63306;" & _
"User Id=admin;Password=test"
EDIT
编辑
I have noticed that qry
is not declared as a string either, you may need to do the same with this as I suggested with strconn
.我注意到
qry
也没有声明为字符串,您可能需要像我对strconn
建议的那样做同样的strconn
。
dim qry as string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.