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

ID: Q189683


The information in this article applies to:
  • ActiveX Data Objects (ADO), versions 1.5, 2.0, 2.1 SP2
  • Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 5.0, 6.0


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.

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

Additional query words:

Keywords : kbADO kbDatabase kbJET kbVBp500 kbVBp600 kbGrpVBDB kbGrpMDAC kbDSupport kbMDAC200 kbADO210sp2 kbMDAC210SP2
Version : WINDOWS:1.5,2.0,2.1 SP2,5.0,6.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: November 10, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.