473,386 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

MS Access 2003 - Refresh a textbox's calculation

Hi there,

I have a job details form - on that form I have fields to store the job rate, expenses and number of days this rate/expenses applies e.g. rate £150, expenses £24 for 3 days.

I have 2 unbound textfields:
TotalRate (rate * no of days)
TotalExpenses (expenses * no of days)

This then calculates the invoicetotal:
Expand|Select|Wrap|Line Numbers
  1. Me!InvoiceTotal.Value = [TotalRate] + [TotalExpenses]
There's a possibility that the rate/number of days worked/expenses may change after a project has been commissioned, is there anyway to refresh that invoice total text box automatically without having to write that code on the afterupdate event for every textbox that may effect the total?
Jan 10 '07 #1
6 13839
ADezii
8,834 Expert 8TB
Hi there,

I have a job details form - on that form I have fields to store the job rate, expenses and number of days this rate/expenses applies e.g. rate £150, expenses £24 for 3 days.

I have 2 unbound textfields:
TotalRate (rate * no of days)
TotalExpenses (expenses * no of days)

This then calculates the invoicetotal:
Expand|Select|Wrap|Line Numbers
  1. Me!InvoiceTotal.Value = [TotalRate] + [TotalExpenses]
There's a possibility that the rate/number of days worked/expenses may change after a project has been commissioned, is there anyway to refresh that invoice total text box automatically without having to write that code on the afterupdate event for every textbox that may effect the total?
You did not specify whether or not the [InvoiceTotal] Field is Bound/Unbound. If it is Unbound, you can place this code in the Control Source property of the Text Box:
Expand|Select|Wrap|Line Numbers
  1. =([Rate]*[no of days])+([Expenses]*[no of days])
Now, any time you enter a Value in either the [Rate], [no of days], or [Expenses] Field, and move Focus from either Field, [InvoiceTotal] will dynamically be updated and the only line of code will reside in the ControlSource property of this Field. Data is literally being "Pulled" from these Fields. Remember, this can occur only if the [InvoiceTotal] Field is Unbound. Hope this helps.
Jan 10 '07 #2
NeoPa
32,556 Expert Mod 16PB
There's a possibility that the rate/number of days worked/expenses may change after a project has been commissioned, is there anyway to refresh that invoice total text box automatically without having to write that code on the afterupdate event for every textbox that may effect the total?
Not if I understand your explanation correctly.
If any of the values (which affect the total result) changes on the form then the total needs to be recalculated.
However, the code doesn't need to be duplicated.
You can simply have a private procedure which does the work and the AfterUpdate events of the various controls simply call this.
This is not like Excel where you can have event procedures for a workbook which capture the same events as those for an individual worksheet.
Jan 10 '07 #3
Sorry, I should have said the InvoiceTotal textbox is bound.

So what you're saying is that I should create a prcoedure (maybe a runCode macro?) to perform the calculation and for each textbox (rate/expenses/no of days), I should call the afterUpdate(calculate total or whatever) procedure?

Well that was what I was hoping to avoid, but looks like I do have to call something to perform that calculation each time. Fair enough.

Thanks for that.

On the same subject - today I updated the expenses and it displayed on my invoice subform perfectly - but when I selected a command button to go the print preview for the sales invoice - it was still showing the old expenses total. I had to go to Records ---> Refresh from the menu to refresh before displaying the invoice again - is there a way to write some sort of 'pls refresh all data on this form before displaying the report' command?

I have tried inserting:

Expand|Select|Wrap|Line Numbers
  1. Me!InvoiceTotal.Value = [TotalRate] + [TotalExpenses]
with the OnClick event of the button that will display the report, but it still shows the total BEFORE I updated it.
Jan 10 '07 #4
NeoPa
32,556 Expert Mod 16PB
This is because you are storing a calculated field.
The problem you're getting is exactly the reason that you shouldn't do that in an RDBMS like Access. If you use the calculation everywhere you won't have the problem.
If you insist on doing it this way (saving the calculated result) then you will have to take on updating the field every time one of the component fields changes.
Jan 10 '07 #5
The reason I had to store the invoice total as a calculated field was because I had a query, which identifies the income for any given month. I can't total that income if the invoicetotal is unbound. It can display the calculation on the form, but it wont show that value in datasheet view.

So the only way this will work I guess is if I create a report? Or a form? But even so, how can I add up the total for all jobs in a month if totalrate, totalexpenses and invoicetotal are all unbound?
Jan 13 '07 #6
NeoPa
32,556 Expert Mod 16PB
I don't follow you.
Why can't datasheet view show this calculated value in your query?
Jan 13 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
0
by: Del | last post by:
Thanks in advance for any help. I have a database that was created in Access 2000. Several users have been upgraded to Access 2003. Since upgrading to 2003 we have noticed that one of the...
1
by: cdelaney | last post by:
I have a form that I created a calculation on using 2003. The calculation works exactly like I want it to but ONLY on the first and last record. The calculation does not work/exist on records in...
6
by: migueltxa | last post by:
Hi all, I have a problem with some calculations in MS Access 2003. I have 3 fields (Qty, Price and VolumeUSD) in a form and the following formula: VolumeUSD = Qty * Price. Qty and VolumeUSD...
13
by: Ulv | last post by:
I have a table (TblItems) with fields Lenght, Width and Height as decimalfields. I also have the fields Desc, a text field. In a form I have created this line of code after updating: Desc =...
8
by: elias.farah | last post by:
Hello Everyone, I'm having some very weird behavior on a couple of Access forms. (Not all forms, just some of them). The forms have been working for years, under Access XP/2003 etc, and last...
5
by: ssouhrada | last post by:
Hello, I have a simple loop that adds values to a textbox. I would like to have it refresh the text box every 100 records so that the end user still believes it is processing data (it sometimes...
4
by: zufie | last post by:
I have a main form containing a command SEND button that prompts an email form to pop up. The email address(es) that are supposed to appear on the email form are those corresponding to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.