Results 1 to 3 of 3
  1. #1
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94

    Requery subforms on gotfocus event

    Here's my current predicament:



    I'm trying a new approach on handling the call of forms from another form and the return to the previous form. Instead of closing the forms and sending some parameters or using global variables to handle the return to the previous form once closed, I'm simply hiding the calling form from the called form, storing the previous form as a variable on each form and turning said previous form visible when closing the current form. That way I don't have to restore any information or filter being used on the form when the new one is called. Basically on each form:

    Code:
    Dim frmPrevio As Form
    
    Private Sub Form_Open(Cancel As Integer)
        Set frmPrevio = Screen.ActiveForm
        frmPrevio.Visible = False
    End Sub
    
    Private Sub Form_Close()
        frmPrevio.Visible = True
        frmPrevio.SetFocus
    End Sub
    So far so good. Only some of the changes on those forms might alter information on some subforms of the previous form, so i need to requery those subforms. I did it from the form_close event of the called form (frmPrevio.subform_name.requery) and it worked alright, but those forms might be called from different forms and each of them has a different number of subforms with different names (or none at all). I have a few workarounds in mind, like requerying the whole form instead of the subforms (but that would make me have to restore the form to the current record, restore its filter and content on the filter boxes, and so on) or requerying the appropriate subforms depending on frmPrevio's name. But the ideal solution would be to requery the subforms on the main form's gotfocus event, since the close event of the forms sets the focus on the previous form, but the subforms are not requerying when I add Me.subfrm_name.requery on the gotfocus event of the main form. What am I missing? Is it possible to requery the subforms when setting the focus to the main form?

    Thanks for your help

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Form GotFocus doesn't work when there are any controls that can get focus.

    Do this experiment. Create a form with only a line control on it. Code in form GotFocus event: MsgBox "Test". Open form. What happens?
    Now add a textbox. Open form. What happens?
    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
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    Interesting. Then I guess manually calling the event from the close event of the closing form should work. Will try later.

    Thanks for the input June!

    Edit: Yep, working nicely. Thanks again, June.

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

Similar Threads

  1. Replies: 14
    Last Post: 09-15-2017, 11:25 AM
  2. Replies: 5
    Last Post: 03-14-2017, 03:30 PM
  3. Replies: 3
    Last Post: 06-24-2015, 06:25 PM
  4. Replies: 2
    Last Post: 04-08-2015, 04:06 PM
  5. moving between subforms using wrong event?
    By jmoore in forum Programming
    Replies: 8
    Last Post: 08-02-2011, 11: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