How to Disable a Button from the Button's Event Handler?

  • Thread starter Thread starter Jay Chan
  • Start date Start date
J

Jay Chan

I would like to know if there is a way to disable a button when I am
in the middle of the event handler of the same button. MS Access
doesn't allow me to do this:

Private Sub cmdRemoveAll_Click()
...Remove all the stuffs from the list in the form...
Me![cmdRemoveAll].Enabled = False <---- This doesn't work
End Sub

What I am trying to do is:

- I have a form that has a list box.

- The form has a <Remove_All> button that the user can use
to remove all the items from the list box.

- I would like the button to be disabled when the list
is empty or when the user has used the <Remove_All>
button to remove all the items from the list.

How can I get around with this problem?

Thanks in advance for any info.

Jay Chan
 
Jay Chan said:
I would like to know if there is a way to disable a button when I am
in the middle of the event handler of the same button. MS Access
doesn't allow me to do this:

You cannot disable an object if it currently has focus so in your code
before the line that disables the button insert a line to move focus to
some other control.
 
Jay,

I don't believe that you can disable a control while it has
the focus. Try moving your focus to another control before
disabling it...

Private Sub cmdRemoveAll_Click()
...Remove all the stuffs from the list in the form...
' ***
Me![NewControlToGoTo].SetFocus
' ***
Me![cmdRemoveAll].Enabled = False <---- This doesn't
work
End Sub


--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 
I don't believe that you can disable a control while it has
the focus. Try moving your focus to another control before
disabling it...

Thanks for the helpful info that I have received from you and another
newsgroup member.

The problem went away as soon as I move the input focus away from the
button that I want to disable.

Jay Chan
 
Back
Top