Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2004
    Posts
    7

    Unanswered: Removing Focus from control

    Hi, I have a control that I want to disable and lock after it has been used. however because it has the focus I get an error message saying cannot diasble a control while it has the focus.

    "why dont you just set focus to something else" I hear you cry! well trouble is the only other items on the form are lables and images and it will not allow you to transfer the focus to these.

    any ideas on removing the focus would be appreciated.

    heres the code if anyone's interested

    Private Sub Image53_Click()

    Owner_Name.Locked = True
    Owner_Name.Enabled = False

    End Sub

  2. #2
    Join Date
    Jan 2003
    Posts
    81
    I use this technique on all forms.

    Put a small TextBox with the same color as the backgorund somewhere on the form and make it Enabled, Locked and TabIndex=0. Call it RIP. When the form opens the cursor will go to RIP and sit there doing no harm when users but their elbow on their keybord. If for any reason you need to move a focus off a control, use code: Me.RIP.SetFocus.

    Bjorn

  3. #3
    Join Date
    Oct 2004
    Posts
    15

    Focus/Hide - Another Workaround

    I had a similar problem.... I wanted to hide a calendar (made visible by the click of a button) but couldn't use the LostFocus event to make it invisible since the calendar still has focus during the event. Unfortunately, if the user clicked on any number of other controls, the calendar would remain open. I didn't want to create an event on every control to make the calendar invisible.

    Here's my workaround in a nutshell:

    OnClick (of button that opens calendar): Calendar.Tag = "F"
    OnLostFocus (of Calendar): Calendar.Tag = "N"
    OnTimer (of Form): If Calendar.Tag = "N" AND Calendar.Visible = True then Calendar.Visible = False.

    I set the Calendar.Tag to "F" in the beginning in case the calendar needed to be opened more than just once, otherwise, it would still be set to N and would close while still in use.

    Hope this helps!
    Last edited by mschorr75; 02-11-05 at 15:21.

  4. #4
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    To get the focus off the current control you can try
    SendKeys "{TAB}"

    Also if you had no other control to move the focus to, create a small one and hide it under a control that will remain visible.

    Jerry

Posting Permissions

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