I am getting Run-time error '-2147217900 (80040e14) Incorrect syntax new '11999999' when trying to pull data in from a SQL server database in to a Recordset in VBA, this is my first time using VBA so forgive the lack of perfection.
My code is as follows;
Set connection = New ADODB.Connection
Dim newData As ADODB.Recordset
connection.ConnectionString = "my connection string" 'not posting this for security reasons'
connection.Open
Set newData = connectionExecute(BSMARTOpenFaults )
I have my query stored as a multiline string as I prefer it becuase it looks better with SQL statements.
Private Const BSMARTOpenFaults = "select count(*) from call" _
& "where (" _
& " call_id between 11000000 and 11999999" _
& "or call_id between 12000000 and 12999999" _
& "or call_id between 14000000 and 14999999" _
& "or call_id between 16000000 and 19999999" _
& "or call_id between 26000000 and 26999999" _
& "or call_id between 31000000 and 31999999" _
& "or call_id between 73000000 and 73999999)" _
& "and call_status <> 2 -- all open calls" _
& "and call_type = 'FT'"
Judging by the error its falling on the SQL query (or its just a coincedence that the two numbers are the same) but I am not sure on how to fix it because when I run the query on SQL Server Management Studio the query executes and returns a result (21 to be exact) so it is confusing me as to why it won't execute and returns an invalid syntax error when attempting in VBA, is this an incorrect way of formatting SQL statements in VBA?