How to requery a subform at closing of a popup form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaad
    New Member
    • Oct 2009
    • 158

    How to requery a subform at closing of a popup form?

    I use a popup form to write the "ToDo" portion of a record. Once I close the popup form I would like
    Code:
    [Forms]![LocationsTF]![LocationSubTSF].[Form]![CurrentRepairs4LocQF].[Form]
    to be refreshed with the new information that I just wrote in the popup form that I just closed. I don't know why I always end up with this same problem every time; every time there is a different way of refreshing a subform. One day someone really amazingly bright will be able to write the most amazing function in the world "Refresh all".

    OnClose_(Refres hAll)would truly be an amazing function
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    *IF* your opening your form from code you can simply do:
    Code:
    docmd.OpenForm "frm_Popup",acNormal,,,acFormPropertySettings,acDialog
    Me.subFrm.Requery
    Since the frm_Popup is opened in DIALOG mode, the code will not continue to the next line until you close the popup.

    or in the close event of your popup:
    Code:
    Private Sub Form_Close()
      Forms("frm_Main").Requery
    End Sub

    Comment

    • TheSmileyCoder
      Recognized Expert Moderator Top Contributor
      • Dec 2009
      • 2322

      #3
      I have written some code to requery all open forms. I haven't tested how it works on subforms, so why don't you do that yourself and report your results.
      Code:
      Public Sub requeryAllOpenForms()
          Dim frm As Object
          For Each frm In CurrentProject.AllForms
              If frm.IsLoaded Then
                  If frm.CurrentView <> 0 Then 'if currentview is 0, frm is loaded in design view
                      
                      Forms(frm.Name).Requery
                      
                  End If
              End If
          Next frm
          
      End Sub

      Comment

      • jaad
        New Member
        • Oct 2009
        • 158

        #4
        It is a little bit more complicated than what it seems. If you open up the picture "Locations" you will see the form where it all start. When I click [repairs]for an item in the sub-location form, a a "popup repair form" pops up so I can write what I need to do with this {item} that is in a "sub2nd location" which in turn is in a "subLocatio n" which in turn is in a "unit" which in turn is in a "building. " Notice at the top left I have a bunch of IDs reference that comes from many tables. if I requery the form, each sub section of the form default back to the first record in tables which mean I have to backtrack the hierarchy of forms in order to see the result in the "current repairs" subform. What I have been doing to refresh the view is simply change record and work my way back but it is time consuming. Ideally I would need the requery JUST the last form that I wrote in my first message. is that possible?
        Attached Files

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          You should be able to modify the code i gave in post 2:
          Code:
          Private Sub Form_Close()
            Forms("LocationsTF").[LocationSubTSF].[Form].[CurrentRepairs4LocQF].Requery
          End Sub

          Comment

          • jaad
            New Member
            • Oct 2009
            • 158

            #6
            LOL it works! For some reason Which I don't know why it didn't want to work before when I used the line. THis is something that happens very often with my database codes. Sometime they work and sometime they don't. Sometime I will be using a function for a month and then suddenly it stops working for no reason. Is there some sort of bug in Access 2007 with this matter?

            by the way thank you very much for your patience and for helping me out... ;0)

            Comment

            • Romain
              New Member
              • Mar 2014
              • 1

              #7
              Brilliant! Thank you

              Comment

              Working...