Solved

Form/Subform Running Total not Updating

Posted on 2011-02-22
7
440 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
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

828 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