Executing a Query to Insert Data from VBA to MySQL and What Will Said Data Look Like -
i'm trying insert snippets of word document mysql database. did in java, lost formatting of microsoft document, i'm trying same in vba (i'm hoping keep formatting?!). find out if will, need try.. i've set connection , table in mysql can't insert values. throws syntax error on "conn.execute" line.
sub connecttodatabase() ' ' dim conn new adodb.connection dim server_name string dim database_name string dim user_id string dim password string ' dim long ' counter dim sqlstr string ' sql perform various actions dim table1 string, table2 string dim field1 string, field2 string dim rs adodb.recordset dim vtype variant ' server_name = "127.0.0.1" ' enter server name here - database_name = "rmp" ' enter database name here user_id = "root" ' enter user id here password = "password1" ' enter password here set conn = new adodb.connection conn.open "driver={mysql odbc 3.51 driver}" _ & ";server=" & server_name _ & ";database=" & database_name _ & ";uid=" & user_id _ & ";pwd=" & password _ & ";option=16427" ' option 16427 = convert longlong int: strsql = "insert parts(idparts, part 1, part 2, part 3, part 4, part 5) " & _ "values (' " & 2 & " ' , '" & 1 & "' , '" & 2 & "' , '" & 3 & "' , '" & 4 & "' , '" & 5 & "' )" conn.execute strsql close connections on error resume next rs.close set rs = nothing conn.close set conn = nothing on error goto 0 end sub
the .net connector uses uid
odbc connector used vba uses user
. i've ever used option=3
well.
conn.open "driver={mysql odbc 3.51 driver}" _ & ";server=" & server_name _ & ";database=" & database_name _ & ";user=" & user_id _ & ";pwd=" & password _ & ";option=16427" ' option 16427 = convert longlong int:
you can test connection running simple sql query.
strsql = "select * parts;" conn.execute strsql
if throws error, still have issue.
also, in code have spaces either side of 2
. correct?
"values (' " & 2 & " ' ,
Comments
Post a Comment