Requery a subform form another form (1 Viewer)

chrisjames25

Registered User.
Local time
Today, 17:02
Joined
Dec 1, 2014
Messages
401
Hi

I have a form with a subform embedded. WIthin the subform there is a cmd button that when clicked opens another form.

The other form that is opened allows me to edit the names of data in the subform. When i click amend in the pop out edit form the name in the subform of form 1 changes as you would expect.

WHat doesnt occur is the subform in form 1has a sort criteria of ascending and if i changed a name from Adam to William it still appears at top of my subform until i add a new name in form 1 and then the form requeries.

So i am basically asking how do i requery my subform from another form after making the edit. I would like this requery to occur just before i docmd.close on form2

Thank you in advance
 

isladogs

MVP / VIP
Local time
Today, 17:02
Joined
Jan 14, 2017
Messages
18,209
You should be able to use something like this (replacing with your own form/subform names):

Code:
Forms!Form1.SubForm1.Form.Requery

However this may move the subform to the first record.
If so, you either need additional code to return to the record you were on or try this:

Code:
Forms!Form1.SubForm1.Form.Recalc
 

chrisjames25

Registered User.
Local time
Today, 17:02
Joined
Dec 1, 2014
Messages
401
Hi Ridders

TRied your suggestion and i get the following error - Run time error'2465: Application-defined or objectdefined error.

In my code should i be referencing the subform or the child control the subform sits in?
 

MarkK

bit cruncher
Local time
Today, 09:02
Joined
Mar 17, 2004
Messages
8,179
What I would do in this case is expose a public method of the main form to requery it's own subform, so that you don't have to use this kind of reference....
Code:
Forms!SomeForm.SomeSubformControl.Form.Requery
In your case you have a Form1 with a Subform2 on it, and the action on Subform2 opens Form3, correct? And you need the Form3 close procedure to requery your Subform2. OK.
I would expose a public method on Form1 that requeries it's own subform, like ...
Code:
Public Sub [COLOR="blue"]RequerySubforms[/COLOR]()
   Me.Subform1.Requery
   Me.Subform2.Requery
End Sub
Then, in Form3, do...
Code:
Private Sub Form_Close()
   Const FN as string = "Form1"
   If CurrentProject.AllForms(FN).IsLoaded Then Forms(FN)[COLOR="Blue"].RequerySubforms[/COLOR]
End Sub
hth
Mark
 

chrisjames25

Registered User.
Local time
Today, 17:02
Joined
Dec 1, 2014
Messages
401
Cheers Mark, WIll give that a try now and report back.

Just chekcing it is the actual control holding the subform rather than the subform name itself i reference?

I rather sloppily have named the subform control Child585 and actual subform as Frm_AddSubform

Your understanding of my query was correct.
 

chrisjames25

Registered User.
Local time
Today, 17:02
Joined
Dec 1, 2014
Messages
401
GENIUS

thank you so much for solving that one for me and in such a neat way that i can utilise for other things going forward.

Had no idea about the close sub so very useful to know.
 

chrisjames25

Registered User.
Local time
Today, 17:02
Joined
Dec 1, 2014
Messages
401
Follow up question within form 3 i already have defined form 1 as StrForm why wont the following code work.

FOund a workaround but just interested why it wont work

Code:
Const FN As String = StrForm
   If CurrentProject.AllForms(FN).IsLoaded Then Forms(FN).RequerySubforms
 

murray83

Games Collector
Local time
Today, 17:02
Joined
Mar 31, 2017
Messages
728
You should be able to use something like this (replacing with your own form/subform names):

Code:
Forms!Form1.SubForm1.Form.Requery

However this may move the subform to the first record.
If so, you either need additional code to return to the record you were on or try this:

Code:
Forms!Form1.SubForm1.Form.Recalc

was searching for some other sub form stuff but found this and was also needed and helped a great deal saved me asking anwway
 

Users who are viewing this thread

Top Bottom