Results 1 to 9 of 9
  1. #1
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    Requery Main Form, Keep Focus on Subform

    I need to requery main form but still stay on the subform. Tried code below but it it says it can't find the subform.



    Private Sub Form_AfterUpdate() 'Being fired from the subform
    Forms!Categories.Form.Requery ' Refreshes Main From Categories ' Categories is Main form
    Forms!Categories!AddorDeleteProducts.Form.SetFocus ' AddorDeleteProducts is subform
    Attached Thumbnails Attached Thumbnails CategoriesProductsForms.jpg  

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Requerying the main form doesn't necessarily cause subform to lose focus. I just tested that.
    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
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Forms!Categories.Form.Requery ' Refreshes Main From Categories


    This causes the focus to shift to the main form?

  4. #4
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Requerying the main form doesn't necessarily cause subform to lose focus. I just tested that.
    Agreed.

    burrina, have you tried Me.Parent.Requery? The advantage is you don't have to hard code the name of the main form. Beware of situations where requery changes the Link Master Field value.

  5. #5
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Yep, tried that, it still sets the focus on the main form.

  6. #6
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Found the solution. Use Me.Recalc instead. That does the trick!

  7. #7
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    burrina, I'm surprised with what you experience. However, to be exact (look I avoided the term 'pedantic' ), there are two foci involved: one for the main form and one for the subform. You have to use the focus together with the active form and/or the active control. In the case of a main form/subform setup, the active form will always be the main form. The control with the focus on the main form is the active control. If this active control happens to be the subform control, the subform's focus 'takes over' and dictates which control on the subform is effectively the active control. A subform 'remembers' which of its controls has the focus. However because the most common way of entering the subform is by clicking on it, this 'memory' is destroyed and the control underneath the cursor becomes the active control. Try entering the subform by any means other than clicking and the subform is in the state at which you left it.

    This is really a longwinded explanation saying you were on the right track in your original post. If you find that your action is setting the focus/active control away from the subform then simply put it back. The problem was that your code was not quite correct; it should be

    Forms!Categories!AddorDeleteProducts.SetFocus

    Now if Recalc does what you want then I suggest Recalc is what you needed in the first place - Requery goes back to the database and reretrieves the data whreas Recalc simply repeats the calculations for any calculated fields, the database is not requeried.

  8. #8
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2002
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Thanks for explaining that. it helped me a lot. Wish I had learned this when I was young and still had hair and a brain that worked.

    Thanks,
    On top of that, it's my birthday, Yeah! The big 61... Old Fart Am I ...

  9. #9
    Rod is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    Happy birthday! If you're an old fart I don't know what that makes me; I can give you 6 years!

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

Similar Threads

  1. Replies: 1
    Last Post: 11-18-2012, 06:24 PM
  2. Requery subform after update of main form
    By gemadan96 in forum Forms
    Replies: 3
    Last Post: 10-17-2012, 02:33 PM
  3. Replies: 3
    Last Post: 10-09-2012, 11:58 PM
  4. Replies: 3
    Last Post: 04-17-2012, 10:28 AM
  5. Replies: 3
    Last Post: 10-10-2011, 06:33 PM

Tags for this Thread

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