devxlogo

Encase Query Names in Brackets to Avoid ADO/Jet Errors

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.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist