Question : ADO recordset open SQL statement. Error when table name contains an underscore. MyTable_New

The recordset.open method returns an error. The object MyTable_New is not recognized. There is no error when the tablename is MyTableNew.

Here is the scenario:

dim cn as adodb.connection
dim rs as adodb.recordset
set cn = new adodb.connection
cn.open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDatabase;Data Source=eg;Application Name=TestApp"
set rs = new adodb.recordset

rs.CursorType=adOpenStatic
rs.LockType=adReadOnly
rs.CursorLocation=adUseClient

rs.open "Select * from MyTable_New ", cn

Error: There is no object named MyTable_New

The same process works when the table name does not contain an underscore.

If I open SQL Server Management Studio and paste the SQL Statement into the Query window, there is no error. It just does not work from the Access Code behind. SQL statements where a tablename does not contain an underscore work.

Any help or work around would be appreciated.

Answer : ADO recordset open SQL statement. Error when table name contains an underscore. MyTable_New

as I read "frrats_1604..LeaseTerm_Violations", must it not read:

    & "FROM (ms_1604..SiteReq AS SR LEFT JOIN frrats_1604..[LeaseTerm_Warnings] AS WR " _

?
Random Solutions  
 
programming4us programming4us