Solved

adding a calculation on form

Posted on 2013-01-30
8
245 Views
Last Modified: 2013-01-31
hello,
have attached database-
open database and a form comes up- click Item code and name button-
( enter 101 for item code and jim for name)

a Form comes up that displays avg time it takes Jim to work on item code 101-
question:
Is there a way to display also on this form? the total avg time it takes all names listed in the table?
Thank you,
DB101.accdb
0
Comment
Question by:davetough
  • 4
  • 3
8 Comments
 
LVL 11

Expert Comment

by:datAdrenaline
Comment Utility
On your Form2 you can create a text box control with a Control Source expression of:

=DAvg("[Time Spent]","Table1")
0
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 100 total points
Comment Utility
You could use a DSum:

Msgbox DSum("[Time Spent]", "Table1", [Item Code]='101')

Or if the form is bound to that table, and you want too get the Item Code dynamically:

Msgbox DSum("[Time Spent]", "Table1", [Item Code]='" & Me![Item Code] & "'')
0
 
LVL 11

Accepted Solution

by:
datAdrenaline earned 400 total points
Comment Utility
"You could use a DSum"

I thought the Questioner wanted the average of all in Table1? ... but it is unclear about whether or not to filter on the item code.

---

So, if filtering is the desired result, then you can apply the filter LSM created in the DAvg() function:

=DAvg("[Time Spent]","Table1", [Item Code]='" & Me![Item Code] & "'')
0
 

Author Comment

by:davetough
Comment Utility
the first answer worked fine and then I realized I did want to filter on item code-
am attaching error I am getting- can see what am doing wrong- have tried LM solution too and not working-
thank you
error.docx
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:davetough
Comment Utility
will post another question-thank you
0
 
LVL 11

Expert Comment

by:datAdrenaline
Comment Utility
sorry about the error.  the Me keyword is valid in VBA, however in a Control Source expression, you use [Form]

=DAvg("[Time Spent]","Table1", [Item Code]='" & [Form]![Item Code] & "'')

or, you  just drop the form reference since your scope is the current form ...


=DAvg("[Time Spent]","Table1", [Item Code]='" & [Item Code] & "'')
0
 

Author Comment

by:davetough
Comment Utility
thanks - you know I am still getting error-
can you insert code into txtbox on form and attach db back here?

also just to confirm I am doing this right -am inserting code into the control source of the unbound textbox on form ( form2)
thanks
0
 
LVL 11

Expert Comment

by:datAdrenaline
Comment Utility
This ...

=DAvg("[Time Spent]","Table1", [Item Code]='" & [Form]![Item Code] & "'') 

Open in new window


Should be this ...

=DAvg("[Time Spent]","Table1", "[Item Code]='" & [Form]![Item Code] & "'") 

Open in new window


Pay close attention to the quotes!  It seems that LSM inadvertently did not balance the quotes and I copy pasted from him <dazed> ... So, I think I got it right this time!  {note: I am not in a position to post a sample, so hopefully this will do the trick!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now