Results 1 to 4 of 4
  1. #1
    EddieN1 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    May 2011
    Posts
    316

    Setting Focus to subform from mainform

    I am running an Access 2010 front end with a SQL Server backend. I have a number of form/subform scenarios with a control named LastField in the main form. The idea is to allow the operator to enter/tab through the fields on the main form and then at the end of the main form fields, pass control to the control named "Type" in the subform named sfrm_Detail. The LastField control is hidden from the operator and has an OnEnter event with code like...



    Me!sfrm_Detail.SetFocus

    Me!sfrm_Detail!Type.SetFocus

    This logic works perfectly about 98 percent of the time. However, on occasion, the system throws a Runtime Error of...

    Runtime Error; 2110 - [Database Name] can't move the focus to the control sfrm_Detail.

    I have added an On Error Handler that makes 5 attempts to "Resume" before falling to the Runtime Error and this usually works (I have a audit trail for these things.) on the first re-attempt. However, on occasion, even this fails.

    Has anyone else experienced this and, if so, how did you solve the problem. Thank, Eddie

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by EddieN1 View Post
    ...The LastField control is hidden from the operator...
    I have had mixed success with setting focus on forms. I have not understood why it works sometimes and not others. I am surprised you are able to set focus on a control that is hidden from the operator. If I was trying to automate setting focus on a control, I would use the Lost Focus event of the other control (last control in the Tab Order).

    The problem you are experiencing is probably associated with
    Me!sfrm_Detail.SetFocus

    And if you simply go straight to
    Me!sfrm_Detail!Type.SetFocus

    You will probably avoid future headaches.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by ItsMe View Post

    ...I have had mixed success with setting focus on forms. I have not understood why it works sometimes and not others...
    One of the many quirks of Access is that if one or more Controls on a Form can receive Focus, then the Form itself cannot have Focus.

    • If a Form is only populated with Labels (which cannot have Focus) the Form can receive Focus.
    • If the Form has Textboxes, Comboboxes, Checkboxes, etc., but they are all Disabled, the Form can receive Focus.
    • But if a single Control can receive Focus...then the Form cannot receive Focus!


    Setting Focus on a Control on a Subform requires first setting Focus to the Subform Control (not the Form on the Subform, but the actual Subform Control) and then set Focus on the Control on the Subform.

    This can be confusing, at times, and 'may work sometimes and not at other times,' because when the Wizard is used to set up the Subform, it gives the Subform Control the same name as the Form the Subform is based on! Best practice, to avoid confusion, is to give the Subform Control a name different from that of the Form.

    Linq ;0)>

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by Missinglinq View Post
    ...Setting Focus on a Control on a Subform requires first setting Focus to the Subform Control (not the Form on the Subform, but the actual Subform Control) and then set Focus on the Control on the Subform....
    I did not know this ... interesting tidbit.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 03-30-2012, 01:47 AM
  2. Setting the focus on a subform
    By Paul H in forum Forms
    Replies: 3
    Last Post: 01-10-2012, 09:17 AM
  3. Replies: 2
    Last Post: 09-12-2011, 11:11 AM
  4. Replies: 3
    Last Post: 06-20-2011, 09:30 AM
  5. Setting Focus on a Form
    By MFeightner in forum Forms
    Replies: 1
    Last Post: 07-30-2009, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums