Results 1 to 13 of 13
  1. #1
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    52

    SetFocus on last added form control in subform

    A button on my form adds a new record onto my subform. Once the new record is added, I'd like to SetFocus onto a specific field on that subform.

    Code:
    Private Sub btnAddIngredientRec_Click()
        Dim RecNum As Integer
        RecNum = Me.CurrentRecord
        
        AddIng (RecNum)
        Forms!frmRecipes.SetFocus
        Me.Refresh
    
    '   Here is where I'd like to execute some sort of SetFocus code
    
    End Sub
    
    Private Sub AddIng(RecNum As Integer)
        DoCmd.OpenForm "frmIngredients"
        Forms!frmIngredients.AllowAdditions = True
        DoCmd.GoToRecord , , acNewRec
            ' Link to tbl1Recipe
        Forms!frmIngredients!txtRecipeID = RecNum
            ' Set to Dummy Value
        Forms!frmIngredients!cmbIngredientName = 100
        Forms!frmIngredients.AllowAdditions = False
        DoCmd.Close
    End Sub

    Also, for my own clarification, what's the difference between ! and . when accessing different controls?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    The . in VBA will invoke the intellisense popup tips.

    Is the code behind the main form? Give the subform container a name different from the object it holds, like: ctrDetails

    Me.ctrDetails.Form.controlname.SetFocus
    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
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    52
    Quote Originally Posted by June7 View Post
    The . in VBA will invoke the intellisense popup tips.

    Is the code behind the main form? Give the subform container a name different from the object it holds, like: ctrDetails

    Me.ctrDetails.Form.controlname.SetFocus
    Yes, the code is behind the main form. I renamed the subform container subfrmIngredients. txtIngredientAmt is the control name on my subform.

    It did not work.

    Code:
    Private Sub btnAddIngredientRec_Click()
        Dim RecNum As Integer
        RecNum = Me.CurrentRecord
        
        AddIng (RecNum)
        Forms!frmRecipes.SetFocus
        Me.Refresh
        Me.subfrmIngredients.Form.txtIngredientAmt.SetFocus
    End Sub

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    What does 'did not work' mean - error message, wrong results, nothing happened?

    The technique works for me. If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  5. #5
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    52
    I'm having trouble with the frmRecipesand the code behind it.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    frmRecipes opens from the navigation pane completely blank except for label in form header. Can't do anything. What steps should I follow to reproduce the issue?
    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.

  7. #7
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    52
    I tried to make it smaller by deleting some of the data, and it's causing problems. I am having trouble making the files small enough to attach.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Only need a few records. 2MB zip allowed. You attached only 124KB.
    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.

  9. #9
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    52
    Here's the DB

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    frmRecipes now shows data but no buttons.

    Describe steps to recreate the issue.
    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.

  11. #11
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    52
    Open frmRecipes.
    Click Add button (which shows on mine).
    Click Add Ingredient to Recipe << this is the button I am trying to "fix".

    The functionality is there, but I am wondering if there's a way to SetFocus on the first field of the last record added.

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    I looked at bottom of form. Nothing there. I changed the db to Overlapping Windows and now I see the complete form.

    Try:

    Me.subfrmIngredients.SetFocus
    DoCmd.GoToRecord , , acLast
    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.

  13. #13
    faythe1215 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Posts
    52
    Perfect! Thank you!

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

Similar Threads

  1. SetFocus on Image Control??
    By tylerg11 in forum Forms
    Replies: 1
    Last Post: 07-21-2012, 03:32 PM
  2. Replies: 2
    Last Post: 05-02-2012, 09:16 PM
  3. Replies: 2
    Last Post: 03-21-2012, 10:36 AM
  4. Replies: 11
    Last Post: 02-13-2012, 10:06 AM
  5. Replies: 4
    Last Post: 05-17-2011, 06:56 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