Solved

Form/Subform Running Total not Updating

Posted on 2011-02-22
7
450 Views
Last Modified: 2012-05-11
In my Form/Subform relationship the subform contains a checkbox I would like that each time the checkbox is either set to true or false the running total on the the main form would requery.  It seems to only update after a second action has been performed.  When I check one box my total says $0.00 after I make a second it reflects the total amount from the first selection.

Here is what Im using:


Dim RunningTotal As String
If DCount("*", "[qryRunTotal]") > 0 Then
    RunningTotal = DLookup("[RunTotal]", "[qryRunTotal]")
    Forms!frmToBeAdjusted!Text57 = RunningTotal
Else
    RunningTotal = "$0.00"
    Forms!frmToBeAdjusted!Text57 = RunningTotal
End If

Open in new window

0
Comment
Question by:atreidies
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 14

Expert Comment

by:Bill Ross
ID: 34952359
Hi,

You need to place the calculations in the AfterUpdate event of the checkbox.

Best regards,

Bill
0
 
LVL 1

Author Comment

by:atreidies
ID: 34952391
Ive tried the After/Before events of the subform, form and even the check box they all seem to be one total behind.
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 34952418
Hi again,

In looking at your code if the query relies on data that may nave been updated then you need to save the record.  This is in addition to putting the code in the AfterUpdate event of the checkbox.

Add:

DoCmd.RunCommand accmdSaveRecerd

as the first line in the AfterUpdate event then run your process to get the subtotal.

Regards,

Bill
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 14

Accepted Solution

by:
Bill Ross earned 500 total points
ID: 34952444
Sample...

Pricvate sub_MyCheckBox_AfterUpdate()
  Dim RunningTotal As String
  DoCmd.RunCommand accmdSaveRecord
  If DCount("*", "[qryRunTotal]") > 0 Then
     RunningTotal = DLookup("[RunTotal]", "[qryRunTotal]")
     Forms!frmToBeAdjusted!Text57 = RunningTotal
  Else
     RunningTotal = "$0.00"
     Forms!frmToBeAdjusted!Text57 = RunningTotal
  End If

End sub
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 34952498
Hi,

In general if you are running a query that is using data on the form you need to push that data bak to the db so the query can find the current values.  You can put a running total on the form footer and get the result you are seeking without code if trhe values to be summed up are on the form.

Set the recordsource for Forms!frmToBeAdjusted!Text57

=Sum([FieldName])

That will always display the total.

Bill
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 34952506
Please post the SQL for qryRunTotal
0
 
LVL 1

Author Comment

by:atreidies
ID: 34952524
Perfect once I changed Recerd to Record...thanks!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

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…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

624 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