By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

How to structure Select statement for table & column names that contain spaces

P: 167
Once again... I am supporting another Access database that I did not build. The previous 'owner' of this built the tables with spaces in the table names as well as the column names. I am having a difficult time getting the select statement to work. I am getting a run-time error 2342. "A RunSql action requires and arguement consisting fo an SQL statement.
I am using MS Access 2007. Behind a command button on a form I am building code to select some table data based on a variable.

Table Name: Contract Info
Contract Details Included
Database ID #

Here is my code:
Dim qry as String
Dim rsTemp as New ADODB.Recordset

qry= "Select [Database ID#], [Contract Details Included] from [Contract Info] where [Database ID#] = " & vcVCID & ""
DoCmd.RunSQL qry

End of code

When the DoCmd.RunSql statement runs, I get the error. However I tested creating a query that uses the names with spaces and it works. Here is the code for my query:

Select [Database ID#], [Contract Details Included] from [Contract Info] where [Database ID#] = 2146

I was wondering if I could execute the query above and pass the variable as a parameter? Although I would love to figure out how to get the code to work building my select statement.
Mar 16 '11 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,628
Expand|Select|Wrap|Line Numbers
  1. qry= "Select [Database ID#], [Contract Details Included] from [Contract Info] where [Database ID#] = " & vcVCID 
Mar 16 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.