A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Parameter in Union Query



 
 
Thread Tools Display Modes
  #1  
Old May 25th, 2010, 07:58 PM posted to microsoft.public.access.queries
Jill
external usenet poster
 
Posts: 166
Default Parameter in Union Query

I inherited about ten databases, Year2001, Year2002, etc. These databases are
not related, even though they have information about same ID's (For example,
ID 12224 is David Monk in Year2001, Year2002, etc.) Then I often see needs to
compare Year2001 and Year2002, etc. So I built another database, which is a
collection of an essential table from each year. There I created a union
query, which allows me to see a history of, say, David Monk. Problem is, when
I want to see a history of Judy Tyler, I have to type her ID ten times in
SQL. If there is a way I can create a parameter where I put an ID only once,
it would be splendid. Help?
Thank you.
  #2  
Old May 25th, 2010, 08:08 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default Parameter in Union Query

Try the following

Parameter [Enter Name] Text(255);
SELECT *
FROM Year2001
WHERE [TheName] like [Enter Name] & "*"
UNION ALL
SELECT *
FROM Year2002
WHERE [TheName] like [Enter Name] & "*"
UNION ALL
SELECT *
FROM Year2003
WHERE [TheName] like [Enter Name] & "*"


Or use a saved UNION query as the source for another query
SELECT *
FROM Year2001
UNION ALL
SELECT *
FROM Year2002
UNION ALL
SELECT *
FROM Year2003

And then
SELECT *
FROM theSavedUnionQuery
WHERE [TheName] like [Enter Name] & "*"


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Jill wrote:
I inherited about ten databases, Year2001, Year2002, etc. These databases are
not related, even though they have information about same ID's (For example,
ID 12224 is David Monk in Year2001, Year2002, etc.) Then I often see needs to
compare Year2001 and Year2002, etc. So I built another database, which is a
collection of an essential table from each year. There I created a union
query, which allows me to see a history of, say, David Monk. Problem is, when
I want to see a history of Judy Tyler, I have to type her ID ten times in
SQL. If there is a way I can create a parameter where I put an ID only once,
it would be splendid. Help?
Thank you.

 




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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:45 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.