HOWTO: Use ADO to Query a Table with a Space in Its Name

Article translations Article translations
Article ID: 189683 - View products that this article applies to.
This article was previously published under Q189683
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

SUMMARY

ADO allows you to query a table based solely on its name. If just a table name is specified, ADO prepends select * from and executes that query. If the table you want to query is an Access table with a space in its name, you need to place square brackets around the table's name.

MORE INFORMATION

If you want to query the Order Details table in the Access Northwind (NWind.MDB) database that ships with many products using ADO, you need to use code like the following:
   rsOrderDetails.Open "[Order Details]", cnNWind, adOpenStatic, _
                   adLockReadOnly, adCmdTable
				
You can also use the back quote if you need to use the table name with spaces. For example:
   select * from `Order Details`.
				
NOTE: You can only use the back quote in Access. A standard quote will not work.

This information also applies when using the ADO Data Control that ships with Visual Basic 6.0.


SQL Server 7.0 does support columns names with spaces.
       table1 -------- table name
       ff cc  -------- column name
       char(10)-------- column type
				
In ISQL ( aka query analyzer) you can use select [ff cc] from table1
        insert will occur via
        insert into table1([ff cc]) VALUES('xx')
				
If you execute the statement
        set quoted_identifier on 
				
You can use
        select 'ff cc' from table1
				
You can create a table that have column names with spaces like:
        create table table1([col1 xx] integer)
				
A standard quote will not work. Back quotes do not currently work with back end as SQL Server 7.0.

Properties

Article ID: 189683 - Last Review: February 21, 2014 - Revision: 1.3
APPLIES TO
  • Microsoft ActiveX Data Objects 1.5
  • Microsoft ActiveX Data Objects 2.0
  • Microsoft ActiveX Data Objects 2.1 Service Pack 2
  • Microsoft ActiveX Data Objects 2.5
  • Microsoft ActiveX Data Objects 2.6
  • Microsoft ActiveX Data Objects 2.7
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
Keywords: 
kbnosurvey kbarchive kbdatabase kbhowto kbjet KB189683

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com