• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 767
  • Last Modified:

refresh main form from subform without losing place in subform

I need to update some data in the main form from a subform and simply added

The problem is it takes me away from the subform/field. Is there a way I can frefresh the main form without the cursur going back to the beginning of the form?
  • 3
  • 3
1 Solution
You could use a variable to store the primary key of the current record in the subform, then after refreshing the main form, reposition the subform back to that record.

However, it is probably not necessary to requery the main form at all.  If you are simply updating data in a field of the parent record, then do it on the form, instead of executing code to update the table.

For example, instead of this:

CurrentDb.Execute "Update tblInvoices set DatePaid=Date() where InvoiceNum=" & Me.InvoiceNum

... you can simply do this:

Me.Parent!DatePaid = Date()

Best wishes,
Graham Mandeno [Access MVP 1996-2013]
ShawnAuthor Commented:
I tried that but it didn't sum the amount. It copied the total to 0.

Forms![frmInvoices]![TotalPrice] = Me.SumTotalPrice

It seems when I step through it the total gets there....there seems to be a delay when calculating the new total.
I assume SumTotalPrice is a textbox in the subform footer with a ControlSource something like this:

Which event is your code attached to?  It's possible that you need to save the modified subform record and/or requery SumTotalPrice before the new value will be available.

Try this:
Me.Dirty = False ' save current record
SumTotalPrice.Requery ' refresh the total
Me.Parent!TotalPrice = SumTotalPrice ' update parent record

Open in new window

You may find you need line 1 OR line 2, but not both.

-- Graham
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

ShawnAuthor Commented:
neither seemed to work
Which event is your code attached to, and what exactly are you trying to do?
ShawnAuthor Commented:
I found a way to keep my initial code and just set focus on the next field. works nicely. similar to your above mentioned suggestions. thank you.

so I used

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.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now