469,280 Members | 1,813 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,280 developers. It's quick & easy.

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

158 100+
I use a popup form to write the "ToDo" portion of a record. Once I close the popup form I would like
Expand|Select|Wrap|Line Numbers
  1. [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_(RefreshAll)would truly be an amazing function
Feb 7 '11 #1

✓ answered by TheSmileyCoder

You should be able to modify the code i gave in post 2:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.   Forms("LocationsTF").[LocationSubTSF].[Form].[CurrentRepairs4LocQF].Requery
  3. End Sub

6 19202
TheSmileyCoder
2,321 Expert Mod 2GB
*IF* your opening your form from code you can simply do:
Expand|Select|Wrap|Line Numbers
  1. docmd.OpenForm "frm_Popup",acNormal,,,acFormPropertySettings,acDialog
  2. 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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.   Forms("frm_Main").Requery
  3. End Sub
Feb 8 '11 #2
TheSmileyCoder
2,321 Expert Mod 2GB
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.
Expand|Select|Wrap|Line Numbers
  1. Public Sub requeryAllOpenForms()
  2.     Dim frm As Object
  3.     For Each frm In CurrentProject.AllForms
  4.         If frm.IsLoaded Then
  5.             If frm.CurrentView <> 0 Then 'if currentview is 0, frm is loaded in design view
  6.  
  7.                 Forms(frm.Name).Requery
  8.  
  9.             End If
  10.         End If
  11.     Next frm
  12.  
  13. End Sub
Feb 8 '11 #3
jaad
158 100+
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 "subLocation" 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 Images
File Type: jpg currentRepairs.jpg (42.7 KB, 1025 views)
File Type: jpg Locations.jpg (41.5 KB, 1101 views)
File Type: jpg popup.jpg (44.5 KB, 1167 views)
Feb 8 '11 #4
TheSmileyCoder
2,321 Expert Mod 2GB
You should be able to modify the code i gave in post 2:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Close()
  2.   Forms("LocationsTF").[LocationSubTSF].[Form].[CurrentRepairs4LocQF].Requery
  3. End Sub
Feb 8 '11 #5
jaad
158 100+
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)
Feb 8 '11 #6
Romain
1
Brilliant! Thank you
Mar 22 '14 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by SteveS | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.