Solved Requerying a subform in open form when close another form (1 Viewer)

chrisjames25

Registered User.
Local time
Today, 13:09
Joined
Dec 1, 2014
Messages
401
Hi. I have a mainform for my database. WIthin that I have an add variety button and below that in a subform a list of all current varieties. When i click add variety a new form opens and i create a new variety. What i want to be able to do is when i close the add variety form that the mainform/subform requeries and the newly added variety is visible.

I have achieved this on another form where i want the newly added variety to appear instantly in a combo box using the below code:

Code:
Private Sub Form_Close()
  Dim Goat As String
  Dim Goat2 As String
  Goat = "Frm_BatchInput"
  Goat2 = "Hemingford Plants"
   If CurrentProject.AllForms(Goat).IsLoaded Then Forms(Goat).RequeryCBOTier3
   If CurrentProject.AllForms(Goat2).IsLoaded Then Forms(Goat2).RequeryFrm_SubForm
End Sub

THe code relating to goat works correclty so i figured i could do same with goat2 for refreshing a subform but no such luck. Any suggestion how i should reference a subform correctly or is there an easier way than this?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:09
Joined
Oct 29, 2018
Messages
21,358
Hi. One way to achieve it is to open the other form in Dialog mode, so you can easily requery the subform when that form closes. Otherwise, to refer to a subform from outside the form, you can use the full reference syntax like:

Forms!FormName.SubformControlName.Form.Requery
 

chrisjames25

Registered User.
Local time
Today, 13:09
Joined
Dec 1, 2014
Messages
401
Hi. One way to achieve it is to open the other form in Dialog mode, so you can easily requery the subform when that form closes. Otherwise, to refer to a subform from outside the form, you can use the full reference syntax like:

Forms!FormName.SubformControlName.Form.Requery
Hi DB

So to be clear do i add that to my code above and remove the other stuff.

Also for complete clarity on my mainformi have this structure:

Mainform Called Hemingford, childform called Frm_Sub1Form (this has a sourceobject called Frm_VarietyMain) WIthin the Sub1Form there is another child called Frm_SubSub1Form (this has a sourceobject called Frm_VarietyMainSub). It this is subsub i need to refresh.

USing ur code do i reference the child names i.e Sub1Form and SubSub1Form or do i reference the source objects within them.

Hope that makes sense
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:09
Joined
Oct 29, 2018
Messages
21,358
Really, for making sure we refer to the correct object names, it's best if you could upload a sample copy of your db. But if I had to make a guess, I would try the following in the Close event of your second form.

Forms!Heminford.Frm_Sub1Form.Form!Frm_SubSub1Form.Form.Requery

Hope that helps...

Edit: Oops, @MajP was correct. I fixed the typo. Thanks!
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 09:09
Joined
May 21, 2018
Messages
8,463
Looks like a typo
FormRequery
should be
Form.Requery
 

chrisjames25

Registered User.
Local time
Today, 13:09
Joined
Dec 1, 2014
Messages
401
Really, for making sure we refer to the correct object names, it's best if you could upload a sample copy of your db. But if I had to make a guess, I would try the following in the Close event of your second form.

Forms!Heminford.Frm_Sub1Form.Form!Frm_SubSub1Form.Form.Requery

Hope that helps...

Edit: Oops, @MajP was correct. I fixed the typo. Thanks!
Fantastic. Worked a charm. Thank you so much for help on this one. Sometimes there is a ice easy solution (when u know how :) )
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:09
Joined
Oct 29, 2018
Messages
21,358
Fantastic. Worked a charm. Thank you so much for help on this one. Sometimes there is a ice easy solution (when u know how :) )
You're very welcome. @MajP and I were happy to assist. Good luck with your project.
 

Users who are viewing this thread

Top Bottom