Programaticallly creating a query -
09-29-2003
, 09:09 AM
I've got a database and there are tables for every year starting with
2000. In a form, I have set a combo box to read from the mysysobjects
table, and populate the combo box with the names of tables that are
the years.
SELECT ((Right([Name],4))) AS [Year]
FROM MSysObjects
WHERE (((MSysObjects.Name) Like "2*") AND ((MSysObjects.Type)=1));
Now that i've got that working, I want my users to be able to pick the
year from this combo box, then click on a swtichboard button to open a
form. The form would be based on a query that would be dynamicly
created based on the year selected in the combo box.
Here is an example of my current static query:
SELECT Extension, ExtDate, *
FROM Departments RIGHT JOIN 2003 ON Departments.[DEPT #]=[2003].[DEPT
#]
WHERE (((Extension)=Yes) AND ((ExtDate)>=Now())) OR (((Extension)=Yes)
AND ((ExtDate) Is Null));
In every place where it says 2003 I need that table name to be pulled
from what the user selects in the combo box. I'm not quite sure how
to do this though. I've checked Roger's Access Library, but did not
find anything that seemed to be what I needed. Any info would be
helpful.
Thanks in advance!
brian |