CurtisD
CurtisD

Reputation: 173

Access 2007 - LostFocus Event

On a form I have a Command button. After the user clicks the button I want to disable the button so it can't be clicked again. I know that you can't disable a control while it still has the focus. So I created this event procedure:

Sub Command1_LostFocus()
   Me.Command1.Enabled = False
End Sub

After I clicked the command button, and then tabbed to another control, I expected the above Sub to run. But I get the error message "You can't disable a control while it has the focus". I'm surprised because I thought that when the event procedure was executed Command1 had lost the focus.

Any suggestions on how I can disable a Command button after clicking it?

Upvotes: 1

Views: 939

Answers (1)

Gustav
Gustav

Reputation: 56026

Move the focus to another control:

Me!SomeControl.SetFocus
Me!Command1.Enabled = False

And do name your controls something meaningful.

Upvotes: 1

Related Questions