473,396 Members | 1,864 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.

Filter Form Records Using Existing Query

4 Nibble
Hi. Apologies for any incorrect/off technical lingo. Fairly new to Access and would appreciate any help!

I'm trying to create a command button that will filter form records based on an already created query.

I have a main form with 100 records. Each form record is an employee at a company. The main form was created from a table of the 100 employees and shows general employee information. The main form also holds four subforms. The four subforms are questionnaires on various topics.

I created a query that narrows down the employees that have not taken questionnaire #1 (10 employees).

I've tried the following and neither work for me:
DoCmd.OpenForm "MainFormName", acNormal, "QueryName"

DoCmd.ApplyFilter "QueryName"

Interesting enough, I've created a test query using fields ONLY from the main employee table (which the main form was created from), created a test command button using the code above, and the form records filter as expected.

The missing questionnaire query mentioned above was created using fields from BOTH the main employee table and the table that holds the results of questionnaire #1 (with EmployeeID as the link). Think this might be the issue.

How do I create a button that will filter the main form records to show only those 10 records/employees in my query?

Thanks in advance!!
Aug 25 '20 #1

✓ answered by cactusdata

Use this code in the OnClick event of the button, where ID is the primary key of the table and YourQuery is the name of your narrowed-down query:

Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "ID In (Select ID From YourQuery)"
  2. Me.FilterOn = True

3 2478
cactusdata
214 Expert 128KB
Use this code in the OnClick event of the button, where ID is the primary key of the table and YourQuery is the name of your narrowed-down query:

Expand|Select|Wrap|Line Numbers
  1. Me.Filter = "ID In (Select ID From YourQuery)"
  2. Me.FilterOn = True
Aug 26 '20 #2
dylankirs
4 Nibble
Thank you!!! This worked perfectly. Really appreciate the help.
Aug 26 '20 #3
cactusdata
214 Expert 128KB
Great. You are welcome!
Aug 26 '20 #4

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

Similar topics

2
by: dkintheuk | last post by:
Hi all, Using Access 2000 on XP Pro PC. I have a form that is based on a presaved query - all fine with this. I also have a refresh button that takes the values from various unbound...
3
by: Paulo | last post by:
Hi everyone and thanks in advance for helping me. I´ve a form (continuous form) based on a query, wich several data fields are limited for severel fields (unbound text fields) build in footer...
3
by: tushar jadhav | last post by:
Suppose, i hv an 10 columns and next to that other columns in a DB Table. That 10 columns hv same default values & others are retriving from other table and are nearly 1000 records. How can i insert...
4
by: novoselent | last post by:
This seems like it should be an easy thing, but I think I'm missing something simple here...or I'm just going about it all wrong... Using Access 2003 I have a form that lists vehicle service...
16
by: pabs1111 | last post by:
I'm trying to filter the records in a form using a pass through query. strFilter = strFilter & "( eventid in (select FWIPEvent.eventid from FWIPEvent )) " Me.Filter = strFilter Me.FilterOn =...
2
by: zopita | last post by:
Hi! Good morning all the people. I have two tables: Table 1 Table 2 ---------- ----------- A | a E | e B | b1 F | f1 B...
5
by: Annabelle Lee | last post by:
Hey, I am currently working on a form which requires user to enter customer ID and then display corresponding records with that customer ID, ex. customer status, amount spent etc. I did some...
1
by: Randey | last post by:
."}] I have a table that I need to recall certain data according to what I use in a form filter that uses several combo boxes. If the combo box is empty then I want to recall all the data...
2
Seth Schrock
by: Seth Schrock | last post by:
I have a search form that currently pulls up all the records at the beginning and then uses the form's filter property to filter down the results based on what is typed into the search boxes. As...
3
by: moonrb | last post by:
Hi How Can I View Datasheeet On Form When Using "Select Query" By A Command Button. I am using access 2002 Thanks in advance
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.