using combo box values as part of table name in query

  • Thread starter Thread starter DG
  • Start date Start date
D

DG

Good Morning All,

I was wondering if anyone can help me with a question.

I have several tables which have similar data, but for different years.

For example, my tables are called:
data1999
data2000

I want to be able to put the year into a combobox. Then in my query I want
to concatenate the first part of the table (data) and the selected value in
the combo box. So the query would be something like this

Select * from data&[forms]![form1]![combo1]

However; I keep getting syntax errors. Is my approach possible?

Thanks in advance

Dan
 
It's possible, but ill-advised.

You'd be far better to have a single table with all years in it, and add a
"WhatYear"* field to that table.

Then, it would be a case of

SELECT * FROM Data
WHERE WhatYear = [forms]![form1]![combo1]


*I chose "WhatYear", but you might want a more representative name
"DataYear", "AcquisitionYear', whatever. The point is, "Year" is a reserved
word in Access, so you shouldn't just name the field Year.
 
Back
Top