Encase Query Names in Brackets to Avoid ADO/Jet Errors

While using OLE DB Provider for Jet to manage Access databases through ADO from VB, follow this tip to help you access a query defined in your database. If the query name contains blank characters (ASCII code 32), supply this code, enclosing the name in brackets:

 'To access the query by the 'Recordset object's Open method:rs.Open "[Name with blanks]", _ 'Etc.'To access the query by a Command object:cm.CommandText = "[Name with blanks]"

If you don’t, your program will show a runtime error when you try to open the recordset. The OLE DB Provider for Jet databases interprets the supplied string as a SQL statement, which doesn’t match that language syntax. Specifying different values for the Command object’s CommandType property?or specifying different values on the Options argument when invoking the recordset’s Open method?doesn’t fix the problem. You must use the brackets.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: