Filter a subform

D

Damien McBain

I have a form with some unbound textboxes and a subform on it. The subform's
recordsource is a query which is a joining of a number of tables. The main
form has no recordsource. There are no master or child field links between
the main and subforms.

How can I filter the subform based on the contents of the unbound textboxes
on the main form? I want the subform to return zero (or all, doesn't matter)
records when the form opens, then display records on the subform (from the
query) based on what the user enters into the textboxes. Each textbox
represents a field in the subform. I don't mind if the user has to click a
button to exec some code after the relevant boxes are populated. I also want
a blank text box to return ALL related records (rather than none) and would
like the user to be able to use wildcard characters. Am I asking too much?

I have tried creating a new select query which includes the fields I want to
filter by, then creating a command button on the main form and using the new
query as a filter. I don't know how to use the ApplyFilter method to the
subform using a control on the main form or even whether this is the correct
way to approach the problem.

Any assistance appreciated.

cheers,

Damo
 
C

Chris Darnell

If you didn't need the blank text box to return ALL, then, you could simply
have modified the Link Child and Link Master properties of the subform.
However, probably the best approach for you is to have the parent form
change the subform's recordsource property to be a complete SQL statement
and then force the subform to requery. These actions can either be done
from a command button on the master form, or as an action in the AfterUpdate
method of the textbox on the Master form.
 

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