Question:
MS Access: How to calculate something at run time?
anonymous
2010-02-21 08:46:06 UTC
I'm studying for my IGCSE's ICT practcial.

I need to know what something like "calculate this field at run time" means.

How do I do this on Access 2007?
Four answers:
iLC
2010-02-22 22:50:21 UTC
Suppose you have a table called [order detail] in which you have two fields [product quantity] and [unit price]. Now you want to know the [product price] which is a simple mutiplication:



[product price] = [product quantity] * [unit price]



since [product price] can thus be easily calculated you do not need a field in your [order detail] table to store [product price] there by not only saving storage space but also avoiding risk of data inconsistency.



1) On a form, create an unbound text box and in its control source property write the formula as below (with equal sign):



= [product quantity] * [unit price]



this will display the calculated result.





2) In a SQL query you can have the calculated field [product price] as in the following syntax:



SELECT [product quantity], [unit price], [product quantity] * [unit price] AS [product price] FROM [order detail];



best regards,

iLC

http://iLoveCoding.co.uk
john
2010-02-23 15:46:01 UTC
It depends how you approach it.



You could use a calculated query for example.

Or - add your calculation into the control source of the text boxc on the form



something like =[field1]*[field2]



or add some VBA code to do a calculation and run it on an event such as the form load event.



For MS Access ebooks,training,software and tips

http://www.access-databases.com/
anonymous
2016-04-12 14:01:10 UTC
enclose the fields in square brackets, ensure the field names are spelt correctly.
Hiltine Furtado
2016-02-12 01:09:19 UTC
all this is bakwas


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...