Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I build a Query in VB based on multiple Query results

Status
Not open for further replies.

d1trupinoy

Technical User
Dec 11, 2001
14
US
I have 13 Queries which find items based on certain criteria (e.g. find objects that are red, find objects that are square, etc.) I would like to be able to generate a report based on all the objects found from the multiple queries. Keep in mind that the queries may have found the same object. How do I build a query or report using vb that just shows the objects found after all the queries are run. Currently I have 13 recordsets which I know work (e.g. red, square, etc).
 
you can use a UNION query to put them all together:

(this is from my own db so doesnt have your particular field/query names)

Select PartNumber from [SearchResults-ChosenSP] UNION
Select PartNumber from [SearchResults-ChosenCO] UNION
Select PartNumber from [SearchResults-ChosenGB] UNION
Select PartNumber from [SearchResults-ChosenGS];

another example, selecting ALL fields from the queries. the formats of the 13 query results must look the same, and it disregards the field names and just smashes together everything in field1 of every query, then everything in field 2 of every query, etc. so check to make sure you've got everything in the right place.

Select * from [SearchResults-ChosenSP] UNION
Select * from [SearchResults-ChosenCO] UNION
Select * from [SearchResults-ChosenGB] UNION
Select * from [SearchResults-ChosenGS];

how you do this is start a query, from the menu select Query + SQL Specific + Union.
then put in code similar to above but with your own query names.

ok??

g
 
Thank You!. A simple union query was a all I needed to build and now my report just shows the founds products. WooHoo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top