开发者

MYSQL query from EXCEL VBA based on cell content

i am trying to execute simple query from EXCEL via VBA. i want based on A2 cell's value, query should execute. i am trying following to achieve this but need sue help. to connect:

conMySQL.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};" & "SERVER=" & server & ";" & " DATABASE=" & database & ";" & "UID=" & login_user & ";PWD=" & password & "; OPTION=3; PORT=" & port & ";Connect Timeout=20;"

'open the connection
conMySQL.Open

then to query:

strSQL = "SELECT x FROM some_table"; x = A2's value
MySQL.Query (strSQL)

With rsTemporary
      Do Until .EOF
          recordCount = recordCount + 1
          some_variable = ![supcode]
          rsTemporary.MoveNext
      L开发者_如何转开发oop
End With
        MySQL.closeCon


If your main question is how to get the value from cell A2 as column name in your query you should replace the line with.

strSQL = "SELECT " & Cells(2, 1).Value & " FROM some_table"

or if x is an existing variable containing the value in cell A2:

strSQL = "SELECT " & x & " FROM some_table"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜