dbTalk Databases Forums  

Programaticallly creating a query

comp.database.ms-access comp.database.ms-access


Discuss Programaticallly creating a query in the comp.database.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Brian Ashley
 
Posts: n/a

Default 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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.