1

Is it possible to have a vba variable in MySQL?

SELECT a,b,c
FROM table1 IN <**someVBAvariable**>
WHERE ...

My goal is to be able to re-locate the path of the table to where I want via vba.

EDIT: I understand that VBA can have a global variable, would sql see this?

If this IS possible, would it also work for 2 different sql with 1 vba variable?

4
  • 1
    This is not mysql syntax, this is used in ms access. Mysql is not a file based rdbms like access or paradox, I do not think you can do this. Use linked tables or connect to mysql directly using myodbc and ADO. Commented Oct 28, 2015 at 13:26
  • As Shadow mentioned, you cannot use a VBA variable within an SQL statement. To do so, you would need to connect with the data source using ODBC or ADO within VBA, and then you could use a variable within the SQL statement. Commented Oct 28, 2015 at 13:34
  • So would my best bet would be to update my sql statement from vba file? and not have a vba variable in a sql file Commented Oct 28, 2015 at 13:37
  • You can assemble an SQL statement as string from VBA and thus you can include the content of a variable in it. However, I doubt that this would work for mysql from ms access. My point was: either do not use ms access at all or use linked tables from ms access. You can dinamically link tables from VBA code as well. Commented Oct 28, 2015 at 13:47

1 Answer 1

0

The whole point of SQL is to define an interface between your code and the database so no you would never want to share information between the two except using a database driver - that would be a huge security risk.

It's trivial to form SQL statements in VBA to execute on MySQL see: How can VBA connect to MySQL database in Excel?.

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.