Subforms and filtering

S

Stephen @ ZennHAUS

Hi Guys and Gals

I have what is essentially a contacts database. Each contact has the ability
to have essentially unlimited Addresses, Phone numbers, Email Addresses,
Industry Roles, Available Equipment, Qualifications etc.

As such, I have implemented each of those details about a contact as a
separate table. My problem is that now that I have a form with multiple
subforms, if I try to search or filter based on say a city, piece of
equipment or qualification etc, the main form (which has the general contact
details such as name etc) still displays all records. The subform records
are the only filtered records. So, when scrolling through the list of
contacts, the subform only shows records for those contacts that match the
filter criteria, all other records just show no records in the subform.

How can I filter or search by say City or Equipment with a form like this?

Thanks

Stephen @ ZennHAUS
 
A

Allen Browne

Use a subquery in the Filter of the main form to restrict it to contacts who
have the desired value in the related table.

Here's a basic example that selects the clients who have New York as one of
their addresses:

strFilter = "EXISTS (SELECT AddressID FROM tblAddress WHERE
(tblAddress.ClientID = tblClient.ClientID) AND (tblAddress.City = 'New
York'))"
Me.Filter = strFilter
Me.FilterOn = True

More details and examples of subqueries:
http://allenbrowne.com/subquery-01.html#Search

The final screenshot on that page illustrates a search form where you
combine several subqueries into the filter, i.e. you end up with:
strFilter = "EXISTS (SELECT ...) AND EXISTS (SELECT ...) AND ...
 
S

Stephen @ ZennHAUS

Thanks Allen

Allen Browne said:
Use a subquery in the Filter of the main form to restrict it to contacts
who have the desired value in the related table.

Here's a basic example that selects the clients who have New York as one
of their addresses:

strFilter = "EXISTS (SELECT AddressID FROM tblAddress WHERE
(tblAddress.ClientID = tblClient.ClientID) AND (tblAddress.City = 'New
York'))"
Me.Filter = strFilter
Me.FilterOn = True

More details and examples of subqueries:
http://allenbrowne.com/subquery-01.html#Search

The final screenshot on that page illustrates a search form where you
combine several subqueries into the filter, i.e. you end up with:
strFilter = "EXISTS (SELECT ...) AND EXISTS (SELECT ...) AND ...
 

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

Similar Threads

Filtering subforms via main form 2
Buttons for multiple subforms...? 3
Filtering 25
Subforms 0
Set filter 2
Recordset.Clone Help Needed 9
Specifying conditional Criteria in a Query or Report 6
Subforms Subform 0

Top