Using toggle button to turn filter on and off

G

Guest

I have a toggle button set up on a form to filter data based on criteria
"CHG" in the field. The code I'm using is asking for data even though I
stated the criteria. Basically I just want to filter items identified as
"CHG" when press the toggle and then when I press the toggle again I would
like the filter to be removed. Any help with this would be appreciated.

Here is the code I using;

Private Sub tgDiffActLead_AfterUpdate()
If Me.tgDiffActLead.Value = -1 Then
Me.Filter = "CHG =" & Me.Diff_Action_Lead
Me.FilterOn = True
ElseIf Me.tgDiffActLead.Value = 0 Then
Me.FilterOn = False
End If
End Sub
 
A

Allen Browne

If you open your table in design view, what data type is the CHG field?

If Text, you need extra quotes:
Me.Filter = "CHG = """ & Me.Diff_Action_Lead & """"
Explanation:
http://allenbrowne.com/casu-17.html

If CHG is a Number field, you need to handle the case where it is null,
e.g.:
Me.Filter = "CHG =" & Nz(Me.Diff_Action_Lead,0)

Before Access can apply the filter, it must save any edits. It helps to do
this explicitly before you apply/remove filter, so add this line to the top
of your procedure:
If Me.Dirty Then Me.Dirty = False
(That will give errors if the record cannot be saved.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

message
news:[email protected]...
 

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