Results 1 to 13 of 13
  1. #1
    Join Date
    Nov 2003
    Posts
    104

    Unanswered: Can't Disable Control While it has focus (runtime 2164) [VBA Access 2002]

    I need to disable a button as soon as a user click on it. I cannot get this to work! the code I am using is this:

    Code:
    Private Sub cmdDeleteuser_LostFocus()
    cmdDeleteuser.Enabled = False
    End Sub
    Can Anyone Help Me with this?

    NOTE: The error I get is attached below
    Attached Thumbnails Attached Thumbnails cantdisablecontrol-runtime2164.jpg  

  2. #2
    Join Date
    Sep 2003
    Location
    T.O.
    Posts
    326
    Give something else the focus, the Enabled=False the button

    Private Sub cmdDeleteuser_LostFocus()
    ***SomeOtherControl.SetFocus***
    cmdDeleteuser.Enabled = False
    End Sub
    All code ADO/ADOX unless otherwise specified.
    Mike.

  3. #3
    Join Date
    Nov 2003
    Posts
    104
    That did not work really The Way I wanted to.
    I tried to set the focus to a different button, but it ONLY does that If i manually move the button and click something else. If i click somewhere else on the forum then it sets te focus to the other button and disables this button. I want it to disable this button as soon as it goes in without having the use to have to click somewhere else to do it.

    Any ideas?

  4. #4
    Join Date
    Nov 2003
    Posts
    104

    I am also getting this

    If I try to put this code anywhere else (like in the GotFocus Event) as an example, I get:
    Attached Thumbnails Attached Thumbnails cantsetfocus-runtime2110.jpg  

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Why not do what HomerBoo says within the OnClick event of the button? Ex:

    Private sub MyButton_OnClick()

    MyOtherButton.SetFocus
    MyButton.Enabled=False
    end sub

  6. #6
    Join Date
    Nov 2003
    Posts
    104
    Please read above. I DID do what he had recommended and it did not work the way I wanted. The experiment i was doing with GotFocus was BECASUE it did nto work properly!

  7. #7
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    sub ThisButton_click()
    ThatButton.setfocus
    ThisButton.enabled = False
    end sub

    works IF ThatButton can accept the focus (i.e. it exists, is enabled, is visible)

    izy
    currently using SS 2008R2

  8. #8
    Join Date
    Nov 2003
    Posts
    104
    Nope. Same thing.

    Note that cmdFindUser is both visible and enabled at all times, and yet It cannot accept focus.

    I am clueless at this point as to what to do

  9. #9
    Join Date
    Dec 2003
    Posts
    16

    Re: Can't Disable Control While it has focus (runtime 2164) [VBA Access 2002]

    I use:
    Screen.PreviousControl.SetFocus
    MyButton.Enabled=False

    This will usually work if the control you were on before you clicked could receive focus.

  10. #10
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    this is too strange to play with any more, so fake it!

    add a variable DontDoIt as boolean at the form module level (i.e. above the first sub/func in your form code)

    private sub ThisButton_Click()
    if DontDoIt then
    msgbox "Forbidden!"
    exit sub
    endif
    DontDoIt = True
    'blah
    'blah
    'your one-time code goes here
    'blah
    'blah
    end sub

    ....remebering to
    DontDoIt = False
    before you next want to use ThisButton

    izy
    currently using SS 2008R2

  11. #11
    Join Date
    Nov 2003
    Posts
    1,487
    This is an odd one. Moving focus should work. I can't even generate the error. Maybe try this as the FIRST code in the 'OnClick' event of the button you want to disable (cmdDeleteuser):

    Code:
    Private cmdDeleteuser_Click()
       If whatevercondition Then
           Me.SomeOtherButtonOrControl.SetFocus
           DoEvents
           Me.cmdDeleteuser.Enabled = False
           Exit Sub
       End If
       '....Any  other code.....
       '....You might have.....
       '....       Here        ......
    End Sub
    Strange......
    Last edited by CyberLynx; 12-07-03 at 13:17.

  12. #12
    Join Date
    Nov 2003
    Posts
    104
    I have tried what bluejamul has suggested, but that did the same exact thing. I still get the can't set focus to cmdFindUser error!

    As for the idea of the boolena variable, I CAN do it that way, but that is both unclean and not optimum. There SHOULD be a way to disable the button once you click it. It just makes no sense!

  13. #13
    Join Date
    Sep 2013
    Posts
    1
    Have you tried changing the TakeFocusOnClick property?

    I was having an issue where I cant move focus to another Control when another subform is loaded or after clicking on a msgbox.

    I change the TakeFocusOnClick to false and it solved my issue, but now I cant use SetFocus on that particular button after that (not that I need it anyway).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •