473,386 Members | 1,752 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.

How to calculate Total with a function

102 64KB
Hi friends

I have StartDate and EndDate at my form. I have found a Function GetElapsedTime(interval) which calculate hours & minutes when I give StartDate and Enddate.

At my form TimeSpent is a field and its Control Source is Function GetElapsedTime(interval)
=GetElapsedTimenew([Date2]-[Date])

Now I have to calculate TimeSpent with HourRate. I can't do it bcoz Function.

Can anybody help me.

Thanks
Irshad Ahmed
Jan 27 '15 #1
7 1098
Seth Schrock
2,965 Expert 2GB
You could have another control with its control source being
Expand|Select|Wrap|Line Numbers
  1. =[TimeSpent] * [HourRate]
Personally I would do all the calculations in a query, including your TimeSpent field.
Jan 27 '15 #2
irsmalik
102 64KB
Dear Seth

It is not working. When I try to calculate it gives message.
"#Error".
I also try to run it through query but no result only gives this message.
When I enter Date1 and Date2....TimeSpent calculation is OK.
but it only shows at Form as running sum and does not save in the table. so TimeSpent field in table remain empty.
I assume that TimeSpent control source is a function, not a field, so it is not calculating.

Any more idea or guidance/suggestion. Thanks
Jan 28 '15 #3
Seth Schrock
2,965 Expert 2GB
You shouldn't store calculated values in tables anyway. Let me see if I've got your project correct. You have Date1, Date2, and HourRate which are entered by the user and then you want TimeSpent and Pay to be calculated? If this is correct, then do it in a query and then bind your form to the query.
Expand|Select|Wrap|Line Numbers
  1. SELECT Date1
  2. , Date2
  3. , HourRate
  4. , GetElapsedTimenew(Nz([Date2], 0) - Nz([Date1], 0)) As TimeSpent
  5. , Nz(TimeSpent, 0) * Nz(HourRate, 0) As Pay
  6. FROM Table_Name
You will need to add any other fields that you need and put in your table name and you should be good to go.
Jan 28 '15 #4
irsmalik
102 64KB
Dear Seth

I tried your lines but result is same #Error

My project is attached. I will be really thankful if you please look at that where I am making mistake.
Attached Files
File Type: zip RATES.zip (56.0 KB, 54 views)
Jan 28 '15 #5
Seth Schrock
2,965 Expert 2GB
Please just post the SQL code as I don't open attachments.
Jan 28 '15 #6
irsmalik
102 64KB
OK... here is my query which I open in design mode but for you it is in SQL mode

SELECT [User Time].DATE, [User Time].DATE2, [User Time].RATE, GetElapsedTimenew(Nz([Date2],0)-Nz([Date],0)) AS TimeSpent, [Rate]*[TimeSpent] AS Amount
FROM [User Time];

I will appreciate if you plz open my attached query, it is bcoz i normally make query in query mode not in SQL.

Thanks
Jan 28 '15 #7
Seth Schrock
2,965 Expert 2GB
How you open the query doesn't change anything and the design mode is just Access putting an interface on the SQL code, which is what actually runs.

I notice a few different possible issues. First, Date is a reserved word in Access, and while it is allowed to be used as a field name, it can sometimes cause issues. I would recommend changing to something like Date1 or anything else that isn't a reserved word. You can Google what those are. Second, you don't have the Nz() function around either part of the calculation for Amount. Try adding those and see what happens.
Jan 28 '15 #8

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

Similar topics

1
by: beavenour | last post by:
I am looking for some help creating a more universal function out of this lame attempt at javascript. I have little experience with javascript and want to be able to universalize this function. ...
0
by: Simon Gare | last post by:
Hi, I need to calculate a total based on fields in a repeat region, these values are stored in an SQL db, all are numeric and written in ASP. fields are TOTAL_COST VAT ...
8
by: jimmyg123 | last post by:
Hi, I'm trying to do something similar. This is my javascript <script type='text/javascript'> function totalise(price,total) { var qty = window.document.getElementById('qty').value; var...
2
by: 06mca30 | last post by:
How to calculate total no of hits for my home page?
3
by: tonyhhisc | last post by:
This script calculates the total "listing_fee" based on the price that the user inputs into the "price" field. It works in Firefox but IE says "OBJECT NOT FOUND" please help me debug this, It's...
4
by: kaavitha | last post by:
I am using checkbox list in my project, item1 250 item2 200 item3 300 item4 250 item5 300 so after checking ,the selected items should be redirected to another page with their cost and the...
3
by: John Torres | last post by:
how do you calculate total time hours? I have sub total hours for each day and I've been trying to total all the hours. I'm getting odd numbers. Thanks. John
4
by: Jackwaters | last post by:
I have a problem in that I have an arrayList called pizzaOrders which contains a number of pizza orders. The pizza orders contain information like names, addresses, total price for orders and the...
6
by: amek000 | last post by:
<script language="javascript"> function calcvaluesArr(){ var txts = document.getElementsByName('textfield23'); var aTotal=0; for (var i = 0; i < txts.length; i++) ...
2
by: idealsavran | last post by:
hello.. How can I calculate the total of pages for all file(pdf,word,excel,txt...) types in a directory with c#? please... help!!!
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.