Help with Combo Box filter

  • Thread starter Thread starter bobw
  • Start date Start date
B

bobw

I have a combobox in the form header and I am trying to use it to
filter records by a status of "open" or "closed". Here is the code
that I am using:

Private Sub cmbfilter_AfterUpdate()
status = [Forms]![Log]![cmbfilter]
Me.Filter = "[log]![status] = '" & status & "'"
Me.FilterOn = True
Me.Form.Requery
End Sub

The problem is that when I open the form it is populated with the
first record.
When I select my status in the combo box it automatically updates the
first record with whatever status I am selecting in my filter. How do
I stop this from happening?

Thanks,
Bob W.
 
bobw said:
I have a combobox in the form header and I am trying to use it to
filter records by a status of "open" or "closed". Here is the code
that I am using:

Private Sub cmbfilter_AfterUpdate()
status = [Forms]![Log]![cmbfilter]
Me.Filter = "[log]![status] = '" & status & "'"
Me.FilterOn = True
Me.Form.Requery
End Sub

The problem is that when I open the form it is populated with the
first record.
When I select my status in the combo box it automatically updates the
first record with whatever status I am selecting in my filter. How do
I stop this from happening?

Thanks,
Bob W.

It sounds like your combo box "cmbfilter" is bound to the [status]
field. It should not be. Use a different control to display the status
of the current record, and let cmbfilter be unbound (i.e., leave its
ControlSource property blank).

Note -- this line:
Me.Form.Requery

.... is unnecessary, and should be removed.
 
bobw said:
I have a combobox in the form header and I am trying to use it to
filter records by a status of "open" or "closed". Here is the code
that I am using:
[...]

By the way, I see that you posted variations on this question two
previous times in this newsgroup today. Each of the previous times, you
got replies from very competent people who could have answered your
question if you'd given enough information. They wrote back asking for
more information, and you didn't reply to them, but instead started a
new discussion thread. That's not the way the newsgroups work. Did you
not see their replies?
 
bobw said:
I have a combobox in the form header and I am trying to use it to
filter records by a status of "open" or "closed". Here is the code
that I am using:

Private Sub cmbfilter_AfterUpdate()
status = [Forms]![Log]![cmbfilter]
Me.Filter = "[log]![status] = '" & status & "'"
Me.FilterOn = True
Me.Form.Requery
End Sub

The problem is that when I open the form it is populated with the
first record.
When I select my status in the combo box it automatically updates the
first record with whatever status I am selecting in my filter. How do
I stop this from happening?

I missed it at first, but this line:
status = [Forms]![Log]![cmbfilter]

is setting the value of the current record's [status] field to the value
selected in the combo box.
 
Back
Top