Filter subform via different queries

  • Thread starter fapa via AccessMonster.com
  • Start date
F

fapa via AccessMonster.com

Hi there

I've been told that it's possible to create filtered queries and assign them
to different buttons on a parent form. The aim of doing so, would allows the
form to be more customised.

I'm trying to do this however im having alot of trouble.

I have a form (frm_employee_records) and a subfrom (frm_employee_subform)
that displays a record of all the employees within the database.

I'm trying to create filters that allow the user to customise the records -
for instance, showing the employees with the highest salary/lowest.

The method in which i aim to do this is through buttons. When a user clicks
on a button, the form is filtered to show their answer.

The buttons are:
Highest Salary Employees
Lowest Salary Employees
First Start Date Employees
Lowest Start Date Employees

I've create queries to do this however im not sure how to assign them to the
buttons. I'm told i must change the recordsource and direct each button to
its query however im finding this reeally HARD!

can someone please help! Im trying to find the method in how to do this!

thaaaanks!
 
K

kingston via AccessMonster.com

Change the recordsource of the subform control using the button's OnClick
Event. The subform control may or may not have the same name as the subform.
Check the control name in the main form's design mode; just click on the
subform and look at the properties.

Me.SubFormControlName.Form.RecordSource = "NewQueryName"
 
T

tina

if by "buttons", you mean command buttons (not toggle buttons within an
option group), then try the following in each command button's Click event
procedure, as

Me.RecordSource = "QueryName"
Me.Requery

replace QueryName with the name of the query that goes with the specific
command button.

hth
 
F

fapa via AccessMonster.com

Thanks guys, both ur answered worked great however somehow the salary is no
longer being displayed..

when i click on the "Highest Salary Button" (command button) it shows me the
records i need in the right order (employees with the highest salary) however,
instead of their salary being visible, the textbox displays #Name# so im not
sure what to do! Do you know how/why this happends and how it can be stoped?
 
T

tina

when you change the RecordSource of a form, that doesn't change the
ControlSource of the controls in the form. for instance, if QueryA has a
field named Field3, and that field is bound to a control, then you'll see
the value of Field3 displayed in the control when you look at the data in
Form view. if you change the RecordSource to QueryB, and there is no field
named Field3 in that query, then when you look at the data in Form view, the
control bound to Field3 will show #Name# because there is no field named
Field3 in the form's RecordSource. the moral of this story is: if you're
using different queries as the record source for a single form, then make
sure the fieldnames in all the queries match.

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top