[AccessD] Filter Main Form with Subform...

Susan Harkins ssharkins at gmail.com
Wed Jun 25 16:44:57 CDT 2008


> So I guess from what your saying is that I need to look at using SQL to
> filter the main forms query? How would I apply that SQL to the existing
> query in the main form?  If you could not tell I don't know much about 
> SQL.
> :-(

========Use the subform's Double Click event (or the After Update, whatever 
works best, I just like the Double Click in a subform) to force the main 
form to requery, using the subform's value as the filtering criteria:

Dim strSQL As String
strSQL = "SELECT * FROM table WHERE criteriafield = " &
  subform.Value
Forms!mainform.RecordSource = strSQL

A couple of things -- don't forget to add string delimiters if needed:

strSQL = "SELECT * FROM table WHERE criteriafield = '" &
  subform.Value & "'"
Forms!mainform.RecordSource = strSQL

And that relies on the subform's value equaling the criteria value, which it 
might not -- you'll have to accommodate for that.

But this is just one way -- lots of ways and I think using the subform's 
parent and child link properties to specify the main form is probably easier 
and might have the same results.

Susan H.




More information about the AccessD mailing list