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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Applies Main Form Filter to Subform

Status
Not open for further replies.

briand2

Technical User
Apr 3, 2002
56
GB
Hi all,

I have a main form (BrianMainForm) and it has a subform (BrianSubform). Their recordsources are the same. I wanted to arrange things so that when I apply a filter to BrianMainForm, the filter also gets applied to BrianSubform.

I put the following code in the "Form_Applyfilter" procedure of BrianMainForm:

Private Sub Form_ApplyFilter(Cancel As Integer, ApplyType As Integer)

Me![BrianSubform].Form.Filter = Me.Filter

End Sub

If I right-click any field/textbox on BrianMainForm to get the pop-up menu and I then enter a string in the "Filter For:" box and press return, the filter gets applied (as intended) to both BrianMainForm and BrianSubform. It works every time!! When I first saw this I thought "yippppeee, success, how cool...."!!!!! But my elation was short-lived.

I now wanted to do something slightly differently; instead of right-clicking and using the pop-up menu to filter BrianMainForm, I tried using "Filter By Form". I entered the filter criteria and then, when I pressed the "Apply Filter" button, I got the following message:

Run-time Error '2448':
You can't assign a value to this object.
*The object may be a control on a read-only form.
*The object may be on a form that is open in Design view.
*The value may be too large for this field.

When I choose to Debug, I find the sticking point is at the third line of my routine, i.e. at:

"Me![BrianSubform].Form.Filter = Me.Filter"

Why should this code fail to work just because I applied the filter to BrianMainform in a different way? Could someone please suggest where I'm going wrong?

Thanks,

Brian
 
I'm confused why you are applying a filter to both the main form and subform. If your 'Link Child Fields' and 'Link Master Fields' are correctly set on the subform container there is no need to set a filter for the subform. In fact it could easily provide incorrect information.

Link Child Field: SSN
Link Master Field: SSN

Now the subform will always display information about the person with the SSN in the main form.
-------------------------------------
scking@arinc.com
Try to resolve problems independently
Then seek help among peers or experts
But TEST recommended solutions
-------------------------------------
 
Thanks "scking"!

I'll have a think and a play with it and let you know how I get on!

Regards,

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top