Results 1 to 4 of 4

Thread: Can't set focus

  1. #1
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511

    Red face Unanswered: Can't set focus

    This is a mystery. I have a list box that I make visible and change the rowsource after an option button is clicked. When I then attempt to set the focus on the list box with Me!myListBox.SetFocus, I get the error that the focus can't be moved to this control. So, to test, I add a command button to my form to see if it can take the focus, and I get the same error message "Microsoft Access can't move the focus to the control command93".

    As soon as I choose another option which does not involve this list box (I make the list box invisible), followed by clicking on the option that uses the list box, the setfocus succeeds and every time thereafter. Setting focus consistently fails on the first try only.

    So what causes a visible control to fail to receive the focus on the first try only, in Access 2000?

    Thanks.

  2. #2
    Join Date
    Sep 2002
    Location
    Coventry, Warwickshire, UK
    Posts
    74
    A stab in the dark, but try a .Repaint before you set the focus. It may be Access still thinks the list box is not visible at this time. And of course, you can't set the focus to a control that has .Visible = False.
    Roger Hampson
    XI - ecs (UK) Ltd

  3. #3
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    Me!.Repaint inserted above the SetFocus statement did not resolve this.

    Thanks anyway.

  4. #4
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    Problem resolved, but still a mystery. In VBA I set the focus to a combo box to check a value, then attempted to set focus to the list box, which always failed on the first try but succeeded thereafter. It is as if the combo box would not release the focus. When I skipped setting focus on the combo box, which I learned I did not need to do to get its value, I had no problem setting focus to the list box.

    Resolved.

Posting Permissions

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