Results 1 to 5 of 5
  1. #1
    Shadows1989 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    15

    Automatically move to next subform, first field upon pressing tab on final field

    Hi,

    Wondering if someone can help me:

    Is there a way to move to subform_2 field1, from subform_1, field5 when Tab has been pressed on the keyboard?

    I found this code online, which explained 3 possible ways: https://bytes.com/topic/access/answe...-automatically:

    Code:
    Private Sub PhoneNumber_LostFocus()
    Me.Parent.SetFocus
    Me.Parent!NextSubform.SetFocus
    Me.Parent!NextSubform.Form!NextField.SetFocus
    End Sub
    Which I adjusted to my application, as I gather, I want to use the last possible way, but it doesn't seem to work. Is anyone able to help?

    Code:
    Private Sub field5_LostFocus()
    Me.Parent!Subform_2.Form!Field1.SetFocus
    End Sub
    I've set the Form Cycle in the Property Sheet to be Current Record, so at the moment, when tab is pressed on the last field, it goes back to the first field but ideally, I'd like to to move to the first field on the next subform.

    Should this Form Cycle Property be changed?

    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Instructions say have to execute 3 command lines to set focus to specific control on other subform.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Shadows1989 is offline Novice
    Windows 10 Access 2016
    Join Date
    Oct 2019
    Posts
    15
    Quote Originally Posted by June7 View Post
    Instructions say have to execute 3 command lines to set focus to specific control on other subform.
    Apologies, obviously missed that.

    I changed my code to:

    Code:
    Private Sub Field5_LostFocus()
    Me.Parent.SetFocus
    Me.Parent!Subform_2.Form.SetFocus
    Me.Parent!Subform_2.Form!Field1.SetFocus
    End Sub
    But I get the following error when tabbing from the Field5:

    Code:
    Run-time error '2449':
    
    There is an invalid method in an expression
    I click on Debug and the following is highlighted in error:

    Code:
    Me.Parent!Subform_2.Form.SetFocus
    Any ideas?

  4. #4
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Is one subform nested in the other, or are they both on the main form? Is either of the subforms on a tab control? I believe the code you're trying was not meant for nested subforms - not sure about subform on tab control (have not had coffee yet). Also, the control you want to set focus to cannot be hidden (not sure about disabled). Make sure it can accept focus.

    I would try using an explicit reference by way of the actual forms hierarchy rather than Parent:

    [Forms]![Main form name]![subform control name].[Form]![control name on subform]
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    According to example, remove .Form - should be:

    Me.Parent!Subform_2.SetFocus


    Code works for me.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 11-10-2016, 04:08 PM
  2. Replies: 1
    Last Post: 06-01-2016, 03:04 PM
  3. Replies: 14
    Last Post: 11-04-2015, 09:44 AM
  4. Replies: 3
    Last Post: 12-03-2014, 01:40 PM
  5. Automatically Update Field on Subform?
    By batowl in forum Forms
    Replies: 2
    Last Post: 02-08-2013, 08:16 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