Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Location
    Pacific Northwest
    Posts
    2

    Unanswered: Subform Focus Problem

    I have a form with two subforms. I need to hide some controls on the subforms with code in the On Click event of a command button on the parent form. My problem is that if a control on a subform that I need to hide has the focus when I click the command button I get the error 2165: You can't hide a control that has the focus. I've tried all sorts of different control.Setfocus commands to try to set the focus to other controls on the subform, and on the parent form. No matter what the focus always evidently always stays with the last control that had the focus on the subform before I click the cmd buton. This even happens when my first lne of code in the cmd button's On_Click event sets the focus to the cmdButton I just clicked, and that control even shows the focus outline box, but I still get the error. What am I missing? I'm using Access 2000.

    I sure would appreciate hearing any thoughts anyone may have.

    Thanks!

  2. #2
    Join Date
    Jan 2004
    Location
    Vancouver, WA
    Posts
    41

    Re: Subform Focus Problem

    I was stuck on a similar problem for a while, too.

    The solution I came up with was to place a textbox in the page header of the form (go to View | page Header/Footer to see this). I named mine txtFocusCapture. Then, before you do any disabling of controls in the subform, call a txtFocusCapture.SetFocus.

    The page header and footer will not display with the form, so your focus is removed from any visible controls, allowing you to set visible/enabled states.

  3. #3
    Join Date
    Feb 2004
    Location
    Pacific Northwest
    Posts
    2
    Thanks Mark. Yes, your solution definitely works, and I have another set of forms where I will need to use your solution. In this particular case though I do have some controls on the subform that don't get hidden, so I will just move the focus to one of those before the code to hide the other controls runs.

    Thanks again for your reply, it was much appreciated.

    Best Regards, Ben

  4. #4
    Join Date
    Jan 2004
    Location
    Vancouver, WA
    Posts
    41
    Glad to help. Another note is that if you need to disable the entire subform itself, you will need to use a focus capture control in the page header before doing so.

Posting Permissions

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