Solved

adding a calculation on form

Posted on 2013-01-30
8
254 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
ID: 38836296
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
ID: 38836297
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
ID: 38836887
"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
ID: 38839230
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
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.

 

Author Comment

by:davetough
ID: 38839555
will post another question-thank you
0
 
LVL 11

Expert Comment

by:datAdrenaline
ID: 38839642
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
ID: 38839730
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
ID: 38842376
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

920 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

11 Experts available now in Live!

Get 1:1 Help Now