0

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
      Loop
End With
        MySQL.closeCon

1 Answer 1

1

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.