VBA ADO从MySQL表向Access表插入数据

时间:2017-03-31 19:32:47

标签: access-vba

我想通过Access VBA ADO将MySQL服务器的信息添加到Access表

Dim cnn As ADODB.Connection

cnn.Open "WP1"

CurrentDb.Execute ("delete * from wp_postmeta1;")

cnn.Execute ("INSERT INTO wp_postmeta1 ( meta_id, post_id, meta_key, meta_value ) in '" & CurrentProject.Connection & "' " & _
             "SELECT wp_postmeta.meta_id, wp_postmeta.post_id, wp_postmeta.meta_key, wp_postmeta.meta_value " & _
             "FROM wp_postmeta;")

1 个答案:

答案 0 :(得分:0)

我通过添加连接字符串解决了该问题:

Dim cnn As New ADODB.Connection    
cnn.ConnectionString = "DRIVER={MySQL ODBC 8.0 ANSI Driver};Server=localhost;port=3306;Database=dbo;User=root;pwd=XXXX;Option=3"
cnn.Open

Do While cnn.State <> 1
   DoEvents
   If cnn.State = 0 Then Exit Sub
Loop