Solved

MS Access 2003 Disable Button after Click Event

Posted on 2013-02-06
2
1,034 Views
Last Modified: 2013-02-06
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
Comment
Question by:lrbrister
2 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38860394
Set focus elsewhere first:

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

Open in new window

0
 

Author Closing Comment

by:lrbrister
ID: 38860490
Well...
Duh on me!  Thanks.

Another question coming
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question