Solved

refresh main form from subform without losing place in subform

Posted on 2013-06-18
6
743 Views
Last Modified: 2013-06-18
I need to update some data in the main form from a subform and simply added
Forms![frmInvoices].Refresh.

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?
0
Comment
Question by:Shawn
  • 3
  • 3
6 Comments
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 500 total points
ID: 39258006
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
Me.Parent.Refresh


... you can simply do this:

Me.Parent!DatePaid = Date()

Best wishes,
Graham Mandeno [Access MVP 1996-2013]
0
 
LVL 1

Author Comment

by:Shawn
ID: 39258033
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.
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 39258060
I assume SumTotalPrice is a textbox in the subform footer with a ControlSource something like this:
=Sum([TotalPrice])

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
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 1

Author Comment

by:Shawn
ID: 39258096
neither seemed to work
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 39258299
Which event is your code attached to, and what exactly are you trying to do?
0
 
LVL 1

Author Comment

by:Shawn
ID: 39258375
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
Forms![frmInvoices].Recalc

then
Me.Comments.SetFocus
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question