Use a button only once and reset it.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Impissed
    New Member
    • May 2010
    • 1

    #1

    Use a button only once and reset it.

    OK i have a Microsoft access 2007 and i go VBA through it. What i need is, when I press a button, it should do some calculations and then disable the button. Its like when you click it, you can click the button only once and if you click one more time the data calculated would be wrong. I tried the following code first. Itm_balance and Squantity are field names.

    Private Sub Command18_Click ()
    MsgBox "Do not click this button anymore!"
    Itm_balance = Itm_balance - SQuantity
    Command18.Enabl ed = False
    End Sub

    When i tried it, it gave an error message saying "Run-time error 2164, You can't disable a control while it has focus"
    Can you help me to resolve this error?? You can ask more about my database also if you want. :D
  • vb5prgrmr
    Recognized Expert Contributor
    • Oct 2009
    • 305

    #2
    Do you have another control you can set the focus to? Like a textbox?
    Code:
    Text1.SetFocus
    Command1.Enabled = False
    'do calc..


    Good Luck

    Comment

    Working...