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

Variable Table Name For A Query

P: 10

I'm a novice Access user and have a simple question but can't seem to find the answer.
I have tables imported and named by the user on import e.g. January.
I then need to run a query on the table that the user selects (same query and each table is in the same format so the fields are known).
I have a combo box on the form for the user to select the table on which to perform the query. It's just the table name which is the variable i need to insert into my query.

My SQL for this looks like:
Expand|Select|Wrap|Line Numbers
  1. SELECT field1, field2
  2. FROM Forms!Form1!Combo1
I've tried enclosing with ( ) , [ ] , " " , ' ' , & & but keep getting errors.
Syntax error in FROM clause
Cannot find the input table / query 'Forms!Form1!Combo1' make sure it exists.

I'm sure someone will know the answer...
Thank you
Feb 17 '08 #1
Share this Question
Share on Google+
2 Replies

Scott Price
Expert 100+
P: 1,384
Is this in a standard query, or written into VBA code?

In VBA code the syntax would be: "Select [Field1], [Field2] From " & Forms!Form1.Combo1 & ";"

However, you need to make sure that the combo box in question has as it's bound column the actual name of the table you wish to select from. If the combo box is bound to an invisible column containing a number value, your select statement will be looking for a table with the 'name' of that number value.

Feb 17 '08 #2

Expert Mod 15k+
P: 31,768
As Scott says, it's hard to know what to suggest if you don't say how you're expecting to run the query code you're referring to.
What VBA code are you using at the moment?
Feb 22 '08 #3

Post your reply

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