I am trying to run an SQL query via VBA and seem to be running into an issue with the length of my query.
The query is connecting to a SQL Server table, and is to select particular fields from the table.
The length of the string with the code is ~2100 chars (the field list is built via a loop adding dynamic field names from a row).
I can run the code successfully from within MS SQL Management Studio, so the code is OK. I passed a short query to the macro running the code and it works fine too so it's the length of the SQL string the macro builds which is the problem.
I've researched this problem and it sounds like ~2000 chars isn't outside the character limit so I'm a bit stumped.
I list the SQL code via Debug.Print so I can copy/run it in MSSQL Studio and noticed the code appears to have a line break in it after around 1023 chars so am wondering if the building of the String field is somehow adding a line feed char to the code after some character limit point, which is preventing the SQL from run properly (running it via objRecordSet = str, objConnection but the Record Set never opens).
Any suggestions gratefully accepted.
The query is connecting to a SQL Server table, and is to select particular fields from the table.
The length of the string with the code is ~2100 chars (the field list is built via a loop adding dynamic field names from a row).
I can run the code successfully from within MS SQL Management Studio, so the code is OK. I passed a short query to the macro running the code and it works fine too so it's the length of the SQL string the macro builds which is the problem.
I've researched this problem and it sounds like ~2000 chars isn't outside the character limit so I'm a bit stumped.
I list the SQL code via Debug.Print so I can copy/run it in MSSQL Studio and noticed the code appears to have a line break in it after around 1023 chars so am wondering if the building of the String field is somehow adding a line feed char to the code after some character limit point, which is preventing the SQL from run properly (running it via objRecordSet = str, objConnection but the Record Set never opens).
Any suggestions gratefully accepted.