Hi Everyone
I have an SQL query statement built-up in Excel 2010 VBA, which updates a database, similar to below. I am using ADO and the command .Execute(stSQL) from within Excel VBA - works fine.
I want to take this 'hard coded' query out of Excel, save it, and load it into the variable stSQL from a text file, when require, without any user intervention.Please Login or Register to view this content.
I have copy/pasted and saved this into a text file and I can read this back into the variable stSQL. In this way the query will NOT NOW RUN with .Execute(stSQL). It throws an error which I think comes SQL Server "Incorrect syntax near '&' "
If I manually "Insert" the same text file from the Excel VBE, Insert menu, File ... command, the variable stSQL/query runs OK.
I want the text file to be "imported/inserted/loaded" by VBA, assigned to the variable stSQL and run via VBA code with no user input.
Can anyone help with this please.
I have previously posted this http://stackoverflow.com/questions/1...lude-variables without any success.
With thanks
Barry
Bookmarks