Results 1 to 4 of 4
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Setting Focus from a sub form to a different sub form?

    Code:
    Private Sub cboAddressType_GotFocus()
        If IsNull(Forms!frmBusiness!sfrmBusiness.Form!cboCategoryEntity.Column(0)) Then
     
        MsgBox "You Must Enter Or SELECT an ENTITY before Adding an Address! "
        Forms!frmBusiness!sfrmBusiness.Form!cboCategoryEntity.SetFocus
    'Exit Sub
    End If
    End Sub
    Hi all. I have a primary form and on that are two sub forms.
    When i focus on my second sub form, and the first field is null in subform one


    Then I want to msgbox that, setfocus to the first sub form / Field!


    Main Form = frmBusiness - Single Form
    SubForm 1 = sfrmBusiness - Continous Form - Source Object = sfrmBusinessEntity
    SubForm 2 = sfrmBusinessAddress - Continous Form - Source Object = sfrmBusinessAddress
    Field I am trying to set focus on is in SubForm 1 and is called cboCategoryEntity


    Have tried many things, msgbox works but wont shift the focus?
    Any suggestions please!
    Thanks
    Dave

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Try setting focus to the subform CONTROL, then set focus on the control on the sub form.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Code:
    Private Sub cboAddressType_GotFocus()
     If IsNull(Forms!frmBusiness!sfrmBusiness.Form!cboCategoryEntity.Column(0)) Then
     
        MsgBox "You Must Enter Or SELECT an ENTITY before Adding an Address! "
        Forms!frmBusiness!sfrmBusiness.SetFocus
        
    'Exit Sub
    End If
    End Sub

    Thank you Minty,
    That worked just fine!
    Thanks
    Dave

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You cannot set focus to a form if it has any enabled controls - can't say whether or not that includes enabled but hidden. The last control that had the focus is where the focus will go, not to the form itself. Not sure if you have to set focus to a subform control first, then a control on the subform or whether you can do so directly. Regardless, if the subform contains enabled controls it can't take the focus anyway. What is the purpose of trying to set focus to your subform?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Setting and loosing focus on a sub-form
    By GraeagleBill in forum Forms
    Replies: 4
    Last Post: 05-08-2022, 02:52 PM
  2. Setting focus to an ID in a LISTBOX
    By sarcher in forum Programming
    Replies: 1
    Last Post: 05-05-2020, 11:48 AM
  3. Replies: 3
    Last Post: 06-29-2015, 09:50 AM
  4. Setting focus on a tabbed form
    By crowegreg in forum Forms
    Replies: 21
    Last Post: 08-27-2011, 09:22 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