• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1140
  • Last Modified:

MS Access 2003 Disable Button after Click Event

I have a Button on a form and a VBA Click Event

The code is below...
Getting error message, "Cannot disable control while it has the focus."

How do I handle this?

I need to disable this button so it can only be clicked once.

Private Sub cmdCreateDefaultHours_Click()
    Dim cmd As New ADODB.Command
    Dim rst As New ADODB.Recordset
    cmd.ActiveConnection = Conn
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "HoursTrackingLoadDefaultHours"
    cmd.Parameters("@hoursTrackingID") = Me.txtHTID
    Set rst = cmd.Execute()
    MsgBox rst!msg

'This next line fails
   Me.cmdCreateDefaultHours.Enabled = False
End Sub

Open in new window

0
lrbrister
Asked:
lrbrister
1 Solution
 
mbizupCommented:
Set focus elsewhere first:

Me.SomeOtherControl.Setfocus
Me.cmdCreateDefaultHours.Enabled = False

Open in new window

0
 
lrbristerAuthor Commented:
Well...
Duh on me!  Thanks.

Another question coming
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now