Dynamic Command Buttons

T

Tatakau

I have several buttons that I'd like to enable/disable based on certain
conditions. I think I have the Save Record and Undo Changes buttons figured
out, but I'm having trouble with buttons for a filter form that I made.

The main form has 2 buttons: "Filter Records" and "Remove Filter". I would
like to have the "Remove Filter" button disabled (greyed out) if there is no
filter applied. Is there a flag that I can check to see if the records are
being filtered? I'd like to do something like this:

private sub cmdRemoveFilter_NoFilterBeingUsed()
Me.CmdRemoveFilter.Enabled = False
end sub
private sub cmdRemoveFilter_YesFilterBeingUsed()
Me.CndRemoveFilter.Enabled = True
end sub

Maybe there's a more simple way of doing this...

Thanks,

Nick
 
T

Tatakau

Thanks again, Gunny!

I put the code under Form_Current (took a few tries to find something that
worked!) Though I'm not sure if that is the most efficient place to put
it... is there a better spot?

What is the difference between 'Me!cmdClear.Enabled' and
'Me.cmdClear.Enabled'?

And... should I call you Gunny or Camaro? :p

Thanks!

Nick
 
6

'69 Camaro

Hi, Nick.
is there a better spot?

Place this code wherever you need to enable/disable the button. That could
be in the form's OnCurrent( ) event, in a button's OnClick( ) event, et
cetera.
What is the difference between 'Me!cmdClear.Enabled' and
'Me.cmdClear.Enabled'?

It shows one's preference as a bug-hunter. Those who hate chasing bugs
always use the bang operator when referring to a form's control in code.

Me! (bang operator) always refers to the control. Me. (dot operator) refers
to a form property, unless there isn't one using the name that follows the
dot operator, in which case it refers to the control by that name. If
there's both a form property (a bound field is a form property) and a control
by the same name, then Access selects which one to use by the context. You
might not agree with the selection that Access makes, so you'll have to fix
the occasional bug whenever it comes up.
And... should I call you Gunny or Camaro? :p

I'm a Gunny and my favorite car is a '69 Camaro.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
Top