Reputation: 1
Form A has a button that opens form B which has a continuous subform which needs to filter records based on a field in form A.
The code attached produces the error: runtime error '2491' The action or method is invalid because the form or report isnt bound to a table or query
I suspect the continuous form is the problem as it doesn't appear in the Access forms list but it does have a name in form B however I don't know how to reference it.
Form B is opened from elsewhere without a filter so I don't want to change form B.
CODE: ... DoCmd.OpenForm Formname:="B",wherecondition:="woid = " Forms!A!cmbowoid.Column(0)
Upvotes: 0
Views: 178
Reputation: 1692
Let me guess: Form B has no RecordSource. Only the subform under B does. When you execute the OpenForm
method on Form B, you get the error because the WhereCondition
has no records to act on. The WhereCondition
has no knowledge of (and no effect on) B's subform.
The fix:
1) Use OpenArgs:
DoCmd.OpenForm Formname:="B", OpenArgs:="woid = " Forms!A!cmbowoid.Column(0)
2) In Form B's Form_Load
event, enter this code:
Me.subFormB.Filter = Me.OpenArgs
As long as your OpenArgs
is a valid Filter expression, this should work.
Upvotes: 2