Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Question Unanswered: Set focus does not function as I expect it to do

    Hi.
    In the following code I get the error code 2165: You can't hide a control that has the focus.
    'Page5' is a page on the subform 'Check'.
    'First_Focus' is a text box on the main form where I want to move my focus.

    '************************************************* *****
    If Something = 0 Then
    Forms![Main]!First_Focus.SetFocus
    Forms![Main]![frm-Check].[Form].Page5.Visible = False
    End If
    '************************************************* *****

    Can anyone please help

    Sincerely
    Vestigo

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    It may be that....

    If current focus resides on a Form that differs from the Form which is home to the Control you want to gain focus, then you will need to apply focus to that Home Form first before you can attempt to apply it to the Control.

    Forms!Main.SetFocus
    Forms!Main.First_Focus.SetFocus


  3. #3
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Unhappy Still a Focus problem

    Thanks for your reply, but this has already been tested, it still does'nt function.

  4. #4
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Did you try the Forms("Main").First_Focus.SetFocus edition

    Try to change the Form's name Main to frm_Main also

  5. #5
    Join Date
    Jun 2002
    Location
    Saudi Arabia / Philippines
    Posts
    126
    Something stirs in my memory; I'm sure I've encountered this before. I believe (I have never had the time or inclination to prove this) that there is more than one focus - at least one for each form (or perhaps it's one for each subform). So even if you have moved away from the control and then try to manipulate that control it still has the focus in its local environment. Sorry this is not a very scientific or technical explanation.

    OK, what I suggest you try is to move to page 4 before setting the focus to 'First_Focus'. If I'm right then page 4 has the local focus and you can do what you like with page 5.
    Rod

    fe_rod@hotmail.com

  6. #6
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Unhappy I think I still got the focus.

    Is it so that when I'm on my main form and want to set focus to a control on a subsub form, I need to do the following:

    Set Forms!Main!SubForm1.SetFocus
    Set Forms!Main!SubForm1!Subform2.SetFocus
    Set Forms!Main!SubForm1!Subform2.form!MyControl.SetFoc us


    And the other way around, If I'm on a control at my subsub form and want to set focus to my main form:

    Set Forms!Main!SubForm1!Subform2.SetFocus
    Set Forms!Main!SubForm1.SetFocus
    Set Forms!Main.SetFocus
    Set Forms!Main!MyControl.SetFocus

    **************************************************
    Come on guys, it must be a better way to do this.
    Is there any command to "release" all focus?

    have a nice day
    Sincerely
    Vestigo

  7. #7
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Uh ... HELLO! Think about it ... You can't hide/disable a control that has the focus just like you cannot set the focus to a disabled/hidden control ... If you want to hide/disable do it when the focus is on any other control than that being hidden/disabled ...
    Back to Access ... ADO is not the way to go for speed ...

  8. #8
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Unhappy What's my problem ?

    Exactly, that's the reason I like to move focus to another control.
    Example:
    I press a button in a sub form, afterwards I click on another page in the main form.
    After moving to another page, I would like to disable the button I previously pressed on my sub form.
    To do this I need first to "release" the focus from the button on the sub form.
    THAT’s my problem !!!

    Any proposal would be highly appreciated.


    regards
    Vestigo

  9. #9
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Quote Originally Posted by vestigo
    Exactly, that's the reason I like to move focus to another control.
    Example:
    I press a button in a sub form, afterwards I click on another page in the main form.
    After moving to another page, I would like to disable the button I previously pressed on my sub form.
    To do this I need first to "release" the focus from the button on the sub form.
    THAT’s my problem !!!

    Any proposal would be highly appreciated.


    regards
    Vestigo
    In this instance you need to move the focus to another control in the subform to hide the one you want. Something like:

    Me![SubformControlNameHere].Form.SomeOtherControl.SetFocus
    Me![SubformControlNameHere].Form.OneIWantToHide.Visible=False
    Back to Access ... ADO is not the way to go for speed ...

  10. #10
    Join Date
    Jun 2002
    Location
    Saudi Arabia / Philippines
    Posts
    126
    vestigo

    Did you solve this one? As you can tell from my previous post I'm not at all sure of my facts here but M Owen seems to be saying a similar thing as I vaguely remember. What is fascinating is this following extract from MS VBA Help:

    "Tip You can use the SetFocus method to move the focus to a subform, which is a type of control. You can also move the focus to a control on a subform by using the SetFocus method twice, moving the focus first to the subform and then to the control on the subform."

    It suggests that to move the focus to a sub form control involves two operations. Yes, I realise you are trying to move the focus away from a sub form control but is the double operation true in reverse?

    Another thought: I have sometimes experienced unexpected values in system/application properties and have traced this back to situations where one or more event handler/listener in the chain of calls has probably not completed. A typical situation is where the handler code triggers further events and the handlers for these trigger yet more events, and so on. After everything finishes the system property values are as I expect but during the processing - perhaps a module tests or retrieves a value - then the values are not always what I think they should be. From your descriptions it does not seem likely that you have a complex or convoluted series of events and to be honest I have never encountered this with the focus. However beware of the state of CurrentRecord in these situations.
    Rod

    fe_rod@hotmail.com

Posting Permissions

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