refresh a control from an external form

Hi
On my app I have a form/subform that running Ok but, for the click of a button I need to open another form that adds new records to the table to which the subform  is bound.
It does dos, but the form/subform does not reflect the new entered records when I enter them. To do so, I must close and reopen the form/subform.

But I want to immediately update the subform. I have tried  the .repaint, .requery and .refresh methods but they o not work (repaint dose not repaint and requery/refresh do completely reload the form which is absolutely inconvenient. How can I just "refresh" the subform control from this external form?
João serras-pereiraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
In order for new records to appear, you MUST do a requery. But if it is only the subform, that has new records, you can choose to just requery that subform control.
If the code is being called from the master form itself it could be:
Me.NameOfSubformControl.Requery

Open in new window


If its is being done from a completely different form:
Forms("MasterFormName").NameOfSubFormControl.Requery

Open in new window

Now if its a form in a form in a form...the syntax can quickly become quite cumbersome, and might stop working, if you later redesign.


Often times it is simpler to open the popup form in dialog mode (because this will halt the calling code) and then do the requery when the popup is closed (calling code resumes)
For example, on the main form
Public Sub cmd_add_record_click
  Docmd.Openform "addRecords",,,,,acDialog 'Code pauses here until dialog is closed
  me.SubformControl.Requery
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
Instead of running an append query, you may be able to open the RecordsetClone  of the subform, and directly add the new record:

Set rs = Forms!OtherForm!NameOfSubformControl.Form.RecordsetClone
rs.AddNew
    ' set field values
rs.Update
rs.Close

Open in new window

That should update the subform automatically.
0
Dale FyeCommented:
Anders missed the Form reference:

Change:

Forms("MasterFormName").NameOfSubFormControl.Requery

to:

Forms("MasterFormName").NameOfSubFormControl.Form.Requery

and in his second code snippet:

me.SubformControl.Requery

becomes

me.SubformControl.form.Requery
0
João serras-pereiraAuthor Commented:
Thanks! It immediately worked. I just had to leave the project for 3 hours, so could not respond quicker. Now I am stuck on other part of the form/subform arrangement... will come back to EE...
0
João serras-pereiraAuthor Commented:
oops... sorry I messed all other comments...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.