473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Use results of Query as Parameter in Another Query

11
I'm quite new to VBA and am having trouble figuring this out.

I've got a query that provides a list of users (QryUsers). Using the results of that query I would like to run an INSERT INTO TblResults SELECT TOP 10 * from another query (QryPREPOP). QryUsers and QryPrepop join on the field USER. The number of users in QryUsers can vary based on parameters set in that query.
Jan 14 '14 #1
8 2488
NeoPa
32,556 Expert Mod 16PB
Why not link the two queries in your APPEND query?
Jan 14 '14 #2
muttnut
11
I'm trying to limit my output to only 10 records per user in the user table (I'm creating a list of files to audit) and there can be many more records in my PREPOP table than 10 per user. The entire process as I foresee it is that the manager will run the users query to identify their direct reports and then this VBA job will pull 10 per person...trying to avoid the manager having to run an individual query for each direct report.
Jan 15 '14 #3
zmbd
5,501 Expert Mod 4TB
Let's see if I understand:

You have say 150 supervisors
You want to pull some number, say 10 of these supervisors
each supervisor has a number of employees say 200
and you want to pull only 10 employees for each supervisor

Is this what you are after?
Jan 15 '14 #4
muttnut
11
Not quite....I have 100 managers and each of those managers has 25 direct reports. For each of those 25 direct reports I want to pull 10 files to audit (the PREPOP table contains a list of files the employees worked--which could be 50 or so per employee).
Jan 15 '14 #5
zmbd
5,501 Expert Mod 4TB
Please don't be so litteral.
The numbers I used were arbitray and really don't matter.

The short, qualified answer is: Yes, provided your database schema is correctly designed.

You must have a way to indicate which directs are related to which supervisors and which directs worked on which project-document-whatever.

so a VERY simple schema might be (NOTE: I might not set a database up like this, this is just an example)

tbl_employee
[employee_pk]
[...]

tbl_directs
[directs_pk]
[directs_subordinate_fk_employee] 1:m w/tbl_employee
[directs_supervisor_fk_employee] 1:m w/tbl_employee

tbl_work
[project_pk]
[project_fk_employee]
[...]

Now, create a query against the tbl_directs that returns on [directs_supervisor_fk_employee] the supervisors that you desire = q_s

q_s now becomes the record set you join against a query on tbl_directs to return only the [directs_subordinate_fk_employee] with a matching [directs_supervisor_fk_employee] this is q_d

Take q_d and use it to join against a query on tbl_work so that only [project_fk_employee] matching the [directs_subordinate_fk_employee] on q_d are returned.

I am fairly certain that this could be written all in one go useing SQL.

THERE MAY BE BETTER SOLUTIONS
However, without an understanding of your database schema this is the best I can offer.
Jan 15 '14 #6
muttnut
11
Names are different, but that's basically how I have it set up now....a table with managers and their direct reports and a table with the files which includes the employee associated with the file. What I'm trying to get to is a select top 10 * from the files table for each employee in the employee/manager table.
Jan 16 '14 #7
zmbd
5,501 Expert Mod 4TB
setup the queries as given, in the final query use the TOP predicate (you can use this in the other queries too)

ie:
This is a query on a table of 26 people:
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 10 tbl_people.people_pk
  2. FROM tbl_people;
It will return 10 of them

or
same table
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 10 PERCENT tbl_people.people_pk
  2. FROM tbl_people;
In this case it returns 3 people, rounds up.

Now mind you, this is not a random number... it is the first ten records or the first 10 percent of the records, if you need a random selection that's a horse of a different colour:

You can have a simple random generator or get into some heavier stuff with weighted scores > http://bytes.com/topic/access/answer...ed-probability
Jan 16 '14 #8
muttnut
11
thanks--I already checked with my customer and they are ok with it being the first 10 rather than a random 10. Thanks for your help
Jan 16 '14 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Stan | last post by:
Hello all, I'm looking for some hints as to how to use the results of a query in another query. I assume I'm 'thinking' wrong in how to solve this, so I'm hoping someone can clobber me and send...
0
by: jimmojelsky | last post by:
Access97 database - it is set up to share between several computers - some users have full access, others only have read access - locking is set at "no lock" - everything works unless one of the...
5
by: Daniel Tan | last post by:
Are there anyway to copy rows of records from one query to another query and then hide the records in source query ? Pls advise. Thanks. Regards, Daniel
4
by: blake15 | last post by:
Hey, I'm desperate for a clue in on how ms access can do this: I'd like take the maximum value from one field and then populate another field by dividing the values of the first field by the max. ...
1
by: Ed244 | last post by:
Hi, I'm in the process of producing a database for a college project and have a slight problem I was wondering whether you could help me with. The area I'm having problems with takes a value...
4
by: meendar | last post by:
Hi to all, I just need to get two fields from a table and manipulate the results in next query of a procedure.I planned to code like what you see below, create procedure marks1 as @ sql1 as...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
3
by: robin1983 | last post by:
HI all, how are you ? i need help from you people. This time my problem is that i m running a query inside another query. But, the result that i got is something not exactly what i want. and one...
7
stonward
by: stonward | last post by:
Hi Guys, I feel this should be straightforward, but I'm struggling. I have a listbox that displays the results of a filter/query - including the PK. I need to show just those same filtered...
10
by: Dan Gaffey | last post by:
I'm trying to create a "genius" like search so that a user can enter a song name and it gives you a list of songs of the same genre that should "match". So far I have a search where it can return the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.