Full Version: Refreshing The Main Form After Updating Or Adding A New Record In A Sub-form
UtterAccess Forums > Microsoft® Access > Access Forms
sag
Hello,
I have a main form with a sub-form.
If a user adds/edits or deletes a record in the sub-form (which goes directly against the table), a text box in the main form should get updated with a DSum.
The text box only seems to be getting updated when a record is deleted. However, when I add a new record or edit an existing record, the field does not get updated until the form is closed and then opened again.
I have seen a number of queries on the internet and UtterAccess regarding this, and have tried different code (refresh, requery etc.) but none of them seem to work.
Can I get some ideas on how to accomplish this?
Thank you.
SAG
jleach
What was it you were trying, and were you getting any errors? A Requery of the mainform control should work - something like this (as called from a subform that's one deep (not nested)):
!--c1-->
CODE
Me.Parent.YourDSumControl.Requery

hth
sag
HTH,
I am not getting any errors.
However, when I add a record, I try to add the code to the AfterUpdate event of the last field that I add, but it does not refresh the DSum control in the Main form. I also tried adding this code in the after update event of one of the fields as if I edit it, I want the DSum Control to get updated. But nothing happens.
I wish I could attach the DB, but it is huge and needs a lot of cleanup for confidentiality.
I tried the Docmd runcommand as well, but it does not work.
Thank you.
jleach
Is there perhaps a value that's accidently being missed in the form's BeforeUpdate procedure at all? For instance, I tend to use a Status field fairly often, and I'll set the status to a default on the BeforeUpdate if it's a new record, and a lot of other queries or functionality may depend on one status or another, so missing this could have a similar effect. E.g. - the criteria of the DSum is not including the newly added record.
If you close the form and reopen, will DSum then work as it should?
Odd... if you use the AfterUpdate event of the subform itself (not the control) to requery a main DSum, it should work... if the DSum still isn't reading after closing and reopening the form I'll feel a little better, but if not I'm rapidly running out of ideas.
sag
Thank you so much HTH and JLeach.
My problem was that I was doing a requery on the After Update event of the control (as you mentioned) not on the form.
It works now and I am grateful for your help.
Regards,
jleach
Cool, glad you got it working.
sag
Hello,
I have a new question based on this previous one. I read quite a bit on this, but have not really been able to get it working.
When I add a new record in the sub-form, and start populating the fields, a requery on the 'after update' event of one of the fields pushes the new record to the top (i have a docmd.goto.... bookmark) and it keeps the cursor on the record but the record moves to the top. Is it possible to just allow it to stay at the end until the record is entered.
I do need the requery on the after update of some fields as if the user edits old records, the calculations need to run.
Thank you.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.