Special Edition Using Microsoft Office Access 2003

Spaces in ADO Object Names

When I attempt to open a Command object on the views, functions, or stored procedures of NorthwindCS, I receive a "Syntax error or access violation" message.

SQL Server 7.0+ (unfortunately) supports spaces in object names, such as views and stored procedures. However, SQL Server wants these names enclosed within double quotes. Sending double quotes in an object name string is a pain in VBA, but surrounding the object name with square brackets also solves the problem. For example, cnnName. CommandText = "Sales By Year" fails but cnnName. CommandText = "[Sales By Year]" works. Using square brackets for otherwise-illegal object identifiers is the better programming practice.

Категории