Command Buttons

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

Guest

I would like to disable a command button once it has been clicked,
via code attached to that button. Is this possible?

Any help with this is appreciated. Thanks.
 
I would like to disable a command button once it has been clicked,
via code attached to that button. Is this possible?

Any help with this is appreciated. Thanks.

Code the command button Click event:

' First tell it to do what it is supposed to do.
' Then ...
[SomeOtherControl].SetFocus
Me!CommandButtonName.Enabled = False

Then how are you going to enable it again?
 
This is possible, but requires a little forethought.

- What control should receive the focus before the command button is
disabled?

- When should the button be re-enabled? When a new record is selected?
When a field value changes? When the form re-opens?, etc.

The basic logic is:
'air code

Sub cmdButton_Click()

'run your code

'set the focus to another control
Me.OtherControl.SetFocus

'Disable this button
cmdButton.Enabled = False

End Sub

Many times, I'll Enable or Disable a button depending on value in a
field. Therefore, I'll put something like this into the OnCurrent event
of the form:


'more air code
Sub Form_Current()

If Me!Status = "Processed" then
'move the focus off of the button, if it has it
if screen.activecontrol.name = "cmdButton" then
me.othercontrol.setfocus
me.cmdbutton.enabled = false
end if
else
me.cmdButton.enabled = true
end if
 
Glad I read this. I was just trying to figure out where to put the code for
a button to disable it. What fredg's answer does not address is that you
can't disable a control while it has the focus; however, this issue is, what
control do I set the focus to? Since they will be record navigation buttons,
There is no way to quess where the user may go next. My solution is to set
the focus to one of the other nav buttons. For example, When I hit the first
record, I want to disable First and Previous, so, I guess I will set the
focus to the next button.
 
Back
Top