Filtering in a Form

S

sandrao

I have created a blank form and inserted a "Tab Control form" on it. In this
Tab control from I have placed 4 subforms which I can switch to through the
tabbing method. In one subform I have a command button that will filter the
field “agents†so that I can view the commissions for each “agentâ€
separately.

The code behind the command button is:
Private Sub Label52_Click()
Me.Filter = "[Agent] Like 'Smith'"
Me.FilterOn = True
End Sub

This works fine. But this means that I have to have a command button for
each Agent.

How can I have a combo box “cboSelectAgent†referred to in the above code so
that the Filter will select the name of the agent that is selected and
displayed in an unbound text box?
I think that this will eliminate the need to have a command button for each
agent.

Thanks
 
T

tina

let's say your combobox control has only 1 column, which contains the
agents' names. and let's say the combobox control's name is cboAgent. alter
your code to

Me.Filter = "[Agent] = '" & Me!cboAgent & "'"

notice that i changed the Like to an equal sign. normally, you only use the
Like operator when your criteria contains one or more wildcard characters.
for an exact match, use the equal sign.

hth
 
S

sandrao

Thanks very much....works like a charm

sandrao

tina said:
let's say your combobox control has only 1 column, which contains the
agents' names. and let's say the combobox control's name is cboAgent. alter
your code to

Me.Filter = "[Agent] = '" & Me!cboAgent & "'"

notice that i changed the Like to an equal sign. normally, you only use the
Like operator when your criteria contains one or more wildcard characters.
for an exact match, use the equal sign.

hth


sandrao said:
I have created a blank form and inserted a "Tab Control form" on it. In this
Tab control from I have placed 4 subforms which I can switch to through the
tabbing method. In one subform I have a command button that will filter the
field "agents" so that I can view the commissions for each "agent"
separately.

The code behind the command button is:
Private Sub Label52_Click()
Me.Filter = "[Agent] Like 'Smith'"
Me.FilterOn = True
End Sub

This works fine. But this means that I have to have a command button for
each Agent.

How can I have a combo box "cboSelectAgent" referred to in the above code so
that the Filter will select the name of the agent that is selected and
displayed in an unbound text box?
I think that this will eliminate the need to have a command button for each
agent.

Thanks
 
T

tina

you're welcome :)


sandrao said:
Thanks very much....works like a charm

sandrao

tina said:
let's say your combobox control has only 1 column, which contains the
agents' names. and let's say the combobox control's name is cboAgent. alter
your code to

Me.Filter = "[Agent] = '" & Me!cboAgent & "'"

notice that i changed the Like to an equal sign. normally, you only use the
Like operator when your criteria contains one or more wildcard characters.
for an exact match, use the equal sign.

hth


sandrao said:
I have created a blank form and inserted a "Tab Control form" on it.
In
this
Tab control from I have placed 4 subforms which I can switch to
through
the
tabbing method. In one subform I have a command button that will
filter
the
field "agents" so that I can view the commissions for each "agent"
separately.

The code behind the command button is:
Private Sub Label52_Click()
Me.Filter = "[Agent] Like 'Smith'"
Me.FilterOn = True
End Sub

This works fine. But this means that I have to have a command button for
each Agent.

How can I have a combo box "cboSelectAgent" referred to in the above
code
so
that the Filter will select the name of the agent that is selected and
displayed in an unbound text box?
I think that this will eliminate the need to have a command button for each
agent.

Thanks
 

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