Filter Subform on open

speakers_86

Registered User.
Local time
Today, 18:01
Joined
May 17, 2007
Messages
1,919
I know this shouldnt be to hard, but I haven't messed with Access in a while. Heres what I'm trying to do. On parent form open, filter subform based on a control in the subform. I want to do this from an event inside the parent form. I know it would be easier to do it inside the subform, but I want to reuse this subform again inside the same parent form without a filter, or maybe with a different filter. Here's something I was trying:

Aww...before posting this I had a small amount of success. The following code filters, but it shows no records, when it should so a few.

Code:
Private Sub Form_Current()
Me.frmHomeSub.Form.Filter = Forms![frmhome]![frmHomeSub].Form![seropen] = -1
Me.frmHomeSub.Form.FilterOn = True


End Sub


Also, is this code best off in the open event, or is current or something else better?
 
Hi.. ;)

Try this..:

Code:
Me.frmHomeSub.Form.Filter = "[seropen] = -1"
Me.frmHomeSub.Form.FilterOn = True

or..:

Code:
docmd.applyfilter ,"[seropen] = -1 ","frmHomeSub"

I hope that helps..
 
Yea!!! I used your first one.

Which event is it best to put this in? Typically I would use on open, but I've seen other people commonly using on current.
 
a little bit of this, your purpose is related. If you say every record, on current..
 
Hi.. ;)

Try this..:

Code:
Me.frmHomeSub.Form.Filter = "[seropen] = -1"
Me.frmHomeSub.Form.FilterOn = True
How do I add a second criteria to this?


Code:
'Sets filter for frmHomeSub
Me.frmHomeSubOpen.Form.Filter = "[seropen] = -1"
Me.frmHomeSubOpen.Form.Filter = "[issue] <>'Quarterly'"
Me.frmHomeSubOpen.Form.FilterOn = True

It seems like I need to make the first two lines into one. I tried

Code:
Me.frmHomeSubOpen.Form.Filter = "[seropen] = -1" AND "[issue] <>'Quarterly'"

But that didn't work.
 
Last edited:
Code:
'Sets filter for frmHomeSub
Dim strOpen As String
strOpen = "[seropen] = -1 and [issue]<> 'Quarterly'"
Me.frmHomeSubOpen.Form.Filter = strOpen
 

Users who are viewing this thread

Back
Top Bottom