Yes - it's VBA code. It produces the query in a textbox which I input into SQL. However I want a button on my excel which automatically runs the code produced in SQL without having to manually copy and paste.
Appreciate your help IslaDogs but grateful if you could link it to my code above I have posted. I'm not sure how I would reference my "finalQuery" within your code.
Apologies, first time using this. I believe I need the connection to link VBA to the server used for SQL.
Here's the code I am using currently which generates a userform/textbox where I manually copy and paste the code into SQL and run the query.
Sub UploadSQL()
Application.ScreenUpdating...
Re: Executing SQL query using VBA
When I run: conn.Execute finalQuery, where finalQuery references the string I get the following error:
"Run-time error '-2147217908' Command text was not set for the command object."
I have created a VBA code which generates a userform/textbox with "INSERT INTO ..." statements that I then have to copy and paste into SQL to run. I want to create a button on my userform which: a) automatically runs the query in SQL by referencing the text inside the userform and executing it...