Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I filter a subform using VBA? 1

Status
Not open for further replies.

donnydooner

Programmer
Jan 27, 2003
4
US
I have a form with a subform. I also have a "Search Dialog" form where users enter search criteria in unbound text or combo boxes. I have a visual basic procedure, triggered by a Find Record button on the Search Dialog form.

My problem is, I can't write the VBA code so that it recognizes the field in the subform that I'm trying to filter. My procedure uses the DoCmd.ApplyFilter method and works fine until I try to filter the subform. Can someone help me with this?
 
Instead of DoCmd.ApplyFilter set the subform's recordsource equal to the search criteria.

For example, the subform's record source is purchase order line items. In the search form, the user selects the purchase order number that you wish to display in the subform from a lookup list.

On the close of the search form, set the subform's record source = to the PO Number in the lookup list:

Forms![Main Form]![Sub Form].Form.RecordSource = "Select * from [Purchase Order Line Items] WHERE [PO Number] = '" & Me![PO Lookup] & "' "

Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top