VBA Filtering a subform on a page from a cbobox in subform header

K

Katie

Syntax Help Needed!

I am having difficulty finding the right syntax to make this work.

When the subform is all by itself, it works fine, filtering for contacts of
a particular type, but when it is opened as a subform on a page of a tabbed
sheet on a main form, it does not, and I can't seem to find the syntax to
make it work.

Here is what I have that works for the form by itself:

Private Sub cboFindRelationship_Change()

Me.Filter = "RelationshipType =
forms!frmContactAssignmentSub!cboFindRelationship"

Me.FilterOn = True

End Sub

How do I adjust this so it will work when
the frmContactAssignmentSUb is acting:
as a subform
on a page "pageContacts2"
on a tabset "tabContactsTabset"
on a form "_Company"? The form (complete with underscore) was named before
I got my hands on it.

The combo box is on the subform header, and the field to be filtered is on
the subform detail.

Any help would be appreciated!
 
A

Alex Dybenko

Hi,
try this:

Me.Filter = "RelationshipType = " &
forms![_Company].frmContactAssignmentSub!cboFindRelationship
Me.FilterOn=true

if forms!frmContactAssignmentSub!cboFindRelationship returns a string
value - then you need to add quotes:

Me.Filter = "RelationshipType = '" &
forms![_Company].frmContactAssignmentSub!cboFindRelationship & "'"
Me.FilterOn=true

frmContactAssignmentSub is a name of subform control, normaly it has a name
of a form it holds, but better check this
 
K

Katie

I tried both alternatives, but in both cases got:

"Run Time Error 2465:

Application-defined or object-defined error."

What am I doing wrong?

Katie



Alex Dybenko said:
Hi,
try this:

Me.Filter = "RelationshipType = " &
forms![_Company].frmContactAssignmentSub!cboFindRelationship
Me.FilterOn=true

if forms!frmContactAssignmentSub!cboFindRelationship returns a string
value - then you need to add quotes:

Me.Filter = "RelationshipType = '" &
forms![_Company].frmContactAssignmentSub!cboFindRelationship & "'"
Me.FilterOn=true

frmContactAssignmentSub is a name of subform control, normaly it has a name
of a form it holds, but better check this

--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
When the subform is all by itself, it works fine, filtering for contacts
of
a particular type, but when it is opened as a subform on a page of a
tabbed
sheet on a main form, it does not, and I can't seem to find the syntax to
make it work.

Here is what I have that works for the form by itself:
How do I adjust this so it will work when
the frmContactAssignmentSUb is acting:
as a subform
on a page "pageContacts2"
on a tabset "tabContactsTabset"
on a form "_Company"? The form (complete with underscore) was named
before
I got my hands on it.

The combo box is on the subform header, and the field to be filtered is on
the subform detail.

Any help would be appreciated!
 
A

Alex Dybenko

Hi,
i think you can try to use a expression builder (for example in query
design) to get exact reference to you combo.
perhaps subform control has different name...

--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com


Katie said:
I tried both alternatives, but in both cases got:

"Run Time Error 2465:

Application-defined or object-defined error."

What am I doing wrong?

Katie



Alex Dybenko said:
Hi,
try this:

Me.Filter = "RelationshipType = " &
forms![_Company].frmContactAssignmentSub!cboFindRelationship
Me.FilterOn=true

if forms!frmContactAssignmentSub!cboFindRelationship returns a string
value - then you need to add quotes:

Me.Filter = "RelationshipType = '" &
forms![_Company].frmContactAssignmentSub!cboFindRelationship & "'"
Me.FilterOn=true

frmContactAssignmentSub is a name of subform control, normaly it has a
name
of a form it holds, but better check this

--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com
When the subform is all by itself, it works fine, filtering for
contacts
of
a particular type, but when it is opened as a subform on a page of a
tabbed
sheet on a main form, it does not, and I can't seem to find the syntax
to
make it work.

Here is what I have that works for the form by itself:
How do I adjust this so it will work when
the frmContactAssignmentSUb is acting:
as a subform
on a page "pageContacts2"
on a tabset "tabContactsTabset"
on a form "_Company"? The form (complete with underscore) was named
before
I got my hands on it.

The combo box is on the subform header, and the field to be filtered is
on
the subform detail.

Any help would be appreciated!
 
K

Katie

That worked perfectly! Thanks!

katie

Alex Dybenko said:
Hi,
i think you can try to use a expression builder (for example in query
design) to get exact reference to you combo.
perhaps subform control has different name...

--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com


Katie said:
I tried both alternatives, but in both cases got:

"Run Time Error 2465:

Application-defined or object-defined error."

What am I doing wrong?

Katie



Alex Dybenko said:
Hi,
try this:

Me.Filter = "RelationshipType = " &
forms![_Company].frmContactAssignmentSub!cboFindRelationship
Me.FilterOn=true

if forms!frmContactAssignmentSub!cboFindRelationship returns a string
value - then you need to add quotes:

Me.Filter = "RelationshipType = '" &
forms![_Company].frmContactAssignmentSub!cboFindRelationship & "'"
Me.FilterOn=true

frmContactAssignmentSub is a name of subform control, normaly it has a
name
of a form it holds, but better check this

--
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

When the subform is all by itself, it works fine, filtering for
contacts
of
a particular type, but when it is opened as a subform on a page of a
tabbed
sheet on a main form, it does not, and I can't seem to find the syntax
to
make it work.

Here is what I have that works for the form by itself:

How do I adjust this so it will work when
the frmContactAssignmentSUb is acting:
as a subform
on a page "pageContacts2"
on a tabset "tabContactsTabset"
on a form "_Company"? The form (complete with underscore) was named
before
I got my hands on it.

The combo box is on the subform header, and the field to be filtered is
on
the subform detail.

Any help would be appreciated!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top