By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,916 Members | 1,286 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,916 IT Pros & Developers. It's quick & easy.

How to filter subform in a form using another form?

100+
P: 222
Hello

Working on access 2007. My database file is made on access2003.

I have 2 forms. (categories) and (Productlistsearch).

The Productlistsearch form contain a subform called "Products subform"

I want to open "Productlistsearch" from "categories" where CategoryID in "Products subform" = categoryid in categories.

I tried many syntax but unfortunately I didn't success.
This is my last method that I used.
Expand|Select|Wrap|Line Numbers
  1.  
  2.   Dim stDocName As String
  3.     Dim stLinkCriteria As String
  4.     stDocName = "Productlistsearch"
  5.     stLinkCriteria = "Forms![Productlistsearch]![Products subform].Form![CategoryID]=" & Forms![categories]![CategoryID] & ""
  6.      DoCmd.Close
  7.     DoCmd.OpenForm stDocName, , , stLinkCriteria
Any suggestion would be appreciated

THANK YOU

WASSIM S DACCACHE
Oct 26 '08 #1
Share this Question
Share on Google+
2 Replies


Expert Mod 2.5K+
P: 2,545
Hi Wassim. You cannot filter the subform on open the way you are trying to do - the linkcriterion applies to the main form's recordset, not its subform's one.

You could try opening the form, then filtering the subform using its own filter property as follows. I assume that CategoryID is a string - if it is a number you will not need the single quotes on either side of it in the filter string.
Expand|Select|Wrap|Line Numbers
  1.  
  2.     DoCmd.OpenForm stDocName
  3.     with forms(stDocName)![Products subform].Form
  4.       .filter  = "[Category ID] = '" & Forms![Categories]![CategoryID] & "'"
  5.       .filteron = True
  6.     end with
If you need to close the Categories form before you open the products form then store the value of CategoryID in a variable before you do so, using the variable in place of the direct reference to the CategoryID control in the filter string.

-Stewart
Oct 26 '08 #2

100+
P: 222
Hi Wassim. You cannot filter the subform on open the way you are trying to do - the linkcriterion applies to the main form's recordset, not its subform's one.

You could try opening the form, then filtering the subform using its own filter property as follows. I assume that CategoryID is a string - if it is a number you will not need the single quotes on either side of it in the filter string.
Expand|Select|Wrap|Line Numbers
  1.  
  2.     DoCmd.OpenForm stDocName
  3.     with forms(stDocName)![Products subform].Form
  4.       .filter  = "[Category ID] = '" & Forms![Categories]![CategoryID] & "'"
  5.       .filteron = True
  6.     end with
If you need to close the Categories form before you open the products form then store the value of CategoryID in a variable before you do so, using the variable in place of the direct reference to the CategoryID control in the filter string.

-Stewart
Stewart it worked properly. Appreciate you from the deep of my heart.
you saved my time

Thank you again
Oct 26 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.