Code for toggle that removes filter??

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that is set to open w/certain criteria but I want to add a
toggle box that will remove the filter (and add it again of course) straight
from the form. I know there is the built in toggle on the toolbar but when I
finish this db, i'm not going to give the user access to the toolbars since
it's going to be used by a number of people. Problem is, I don't know the
code to build into the toggle. Would anyone know this?

Thanks!
Heidi
 
Heidi said:
I have a form that is set to open w/certain criteria but I want to add a
toggle box that will remove the filter (and add it again of course) straight
from the form. I know there is the built in toggle on the toolbar but when I
finish this db, i'm not going to give the user access to the toolbars since
it's going to be used by a number of people. Problem is, I don't know the
code to build into the toggle. Would anyone know this?

Thanks!
Heidi

Me.FilterOn = False
Turns it off.

Me.FilterOn = True
Turns it on.

There are additional caveats - see Access online help.
Some versions may behave incorrectly using the VBA toggles.

FWIW,

Dr. Know
 
What is the naming convention for this? I don't have field in my form that
would relate to "FilterOn". Is the toggle named "FilterOn"?

I'm not sure I understand how to put this together - the form gets it's
filter from a command button on a different form - when clicked it opens this
form w/filtered criteria based on the first form. Could you please clarify
what the full vb code should be?

Thanks,
Heidi
 
Revision - sorry I jumped the gun just a bit and didn't realize it was a
built in feature and got it to work half way...BUT it doesn't remove the
filter with just adding the 2 statements in the vb code... If i take out the
2nd, it will remove the filter, it just won't put it back on. So i'm assuming
that because both statements are there, it's negating the first and
therefore, not removing the filter. How should i arrange it so it works
properly?

Thanks!
Heidi
 
Heidi said:
Revision - sorry I jumped the gun just a bit and didn't realize it was a
built in feature and got it to work half way...BUT it doesn't remove the
filter with just adding the 2 statements in the vb code... If i take out the
2nd, it will remove the filter, it just won't put it back on. So i'm assuming
that because both statements are there, it's negating the first and
therefore, not removing the filter. How should i arrange it so it works
properly?

I assumed you were familiar with VBA logic and such.
You stated that you wanted a button that would allow enabling and
disabling the filter from a button on the form.

On the form that you want to en/disable the filter for, place a Text
Box or Command button. In the "On Click" event procedure for that box
or button, link to code behind that form which is similar to the
following: (This example uses a text box rather than a button, so
that special effects can be displayed.)

Private Sub cmdFilter()
Static flg as boolean
If flg Then
Me.cmdFilter.BackColor = 4227072
Me.cmdFilter.SpecialEffect = 2
Me.filter = "Your Filter Criterea"
Me.FilterOn = True
flg = false
Else
Me.cmdFilter.BackColor = 9868950
Me.cmdFilter.SpecialEffect = 1
Me.FilterOn = False
Me.filter = ""
flg = True
End If
End Sub

The flg variable provides the toggle for the text box.
If you call this routine from the form's open event, it will activate
the filter. Pressing the "button" will alternately activate and
de-activate the filter. The filter can either be hard coded in
quotes, as above, or stored in a variable as a string - concatenated
or parsed as any other string.

FWIW,

Dr. Know
 
Thank you - I am still learning (teaching myself really) the VB syntax so
while I know the basics of flow and logic from programming in other
languages, I'm somewhate at a loss w/how to write everything in VB...

Thanks, that works great.

Have a Merry Christmas,
Heidi
 
Heidi said:
Thank you - I am still learning (teaching myself really) the VB syntax so
while I know the basics of flow and logic from programming in other
languages, I'm somewhate at a loss w/how to write everything in VB...

Thanks, that works great.

Languages are similar in many respects - so keep on plugging.
Glad you got it working.
Have a Merry Christmas,

Thanks, and have a Happy Holiday Season.


Greg G.
 

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

Back
Top