Solved

Using an aggregate function in another form without making it read only

Posted on 2014-02-11
5
361 Views
Last Modified: 2014-02-11
Hi,

I have used an aggregate function to count the total number of entries for each pupil in a table. I then wish to use that total filed in another query but when I join the queries together I am not able to edit any of the fields in the original query. How can I show this total and still edit data. I also tried a manual update of the data to a field in the table but it will not let me do that either.

Any help appreciated.

Tricia
0
Comment
Question by:tmckeating
  • 3
  • 2
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39849799
Rather than joining the two queries, you can use a DLookup on the form that needs to display the total.

Add a textbox and set it's control source property to (include the = sign):


= DLookup("YourTotalField", "YourQueryThatCalculatesTheTotal")


See Jim Dettman's article about DLookup here:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_12-Dlookup-and-the-Domain-Functions.html

With that approach, you can display the total without affecting the query that you need to remain editable.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39849811
Also, depending on the recordsource of the form that you need to display the total on....

If the total is based on records *in the form's recordsource*, you can add a textbox to the header or footer section of the form, and use an aggregate function as it's control source:

= SUM(SomeFieldName)


"SomeFieldName" needs to be the name of a field, as it appears in the underlying table... not the name of a textbox on the form.
0
 

Author Comment

by:tmckeating
ID: 39849852
Ok so syntax of these things always throws me I see from your link I have to use something like this

 =Dlookup("[Name]","[tblCompanies]","[CompanyID] =  " & gCurrentCompany)

So if the field name is Total contact and the query is called Countbypupil but its on a continuous form and I only want to return the count for the record that I am currently on, of which the key field is PupilID

=Dlookup([Total],[Countbypupil],[PupilID]= me.[PupilID]    

do I need " " and how do I get it just to return the total for the current pupil?

Thanks
0
 

Author Comment

by:tmckeating
ID: 39849883
Tried this

=DLookUp("[total]","[count by pupil]","[Pupil id] = "" & Me.[pupil id] & "")

says expression is an invalid string
it works with

=DLookUp("[total]","[count by pupil]") but obviously returns the same values for all records.
0
 
LVL 61

Accepted Solution

by:
mbizup earned 300 total points
ID: 39849895
You're close with the first expression... just  too many quotes.

IF PupilID is numeric:

=DLookUp("[total]","[count by pupil]","[Pupil id] = " & [pupil id])

Open in new window



If it is TEXT:

=DLookUp("[total]","[count by pupil]","[Pupil id] = '" & [pupil id] & "'")

Open in new window



Also note that I have dropped the "ME" prefix, which is a VBA term and does not work in property sheets or queries.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article will show you how to use shortcut menus in the Access run-time environment.
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

744 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

10 Experts available now in Live!

Get 1:1 Help Now