Results 1 to 2 of 2
  1. #1
    fritesmodern is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    13

    Setting the focus on a control in a subform

    I have a field (myfield) in a subform (subform). My application sometimes sets the focus back on myfield after it has lost it. Since the focus could be in the main form (mainform), I set the focus first on subform before setting the focus on myfield. The below code fails at frm.SetFocus. What am I missing here? Thanks in advance.






    ‘this fragment code is executed when the focus is in myfield (subform) and the user clicks on a button in the ribbon. The code is actually executed inside the subroutine invoked by the ribbon button.



    Dim ctr As Control
    Dim subfrm As Access.form





    Set ctr = Screen.ActiveControl ‘focus is in myfield which is in subform. Ctr points now to myfield



    Forms!mainform!TextBoxInMainForm.SetFocus ‘focus is moved to a control in main form.



    set subfrm = ctr.Parent ‘this correctly assigns subform to frm



    frm.SetFocus ‘this triggers an error.



    ctr.SetFocus ‘in order for this to work subform must have the focus first since myfield is in a
    ‘subform.
    ------------------------------------------------------------

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    did you try
    Forms!mainform!subform!forms!control.setfocus

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

Similar Threads

  1. Setting Focus to subform from mainform
    By EddieN1 in forum Programming
    Replies: 3
    Last Post: 05-17-2015, 07:12 AM
  2. Replies: 6
    Last Post: 09-17-2014, 01:04 PM
  3. Setting the focus on a subform
    By Paul H in forum Forms
    Replies: 3
    Last Post: 01-10-2012, 09:17 AM
  4. Replies: 2
    Last Post: 09-12-2011, 11:11 AM
  5. Replies: 0
    Last Post: 04-11-2011, 01:39 PM

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