Link to home
Start Free TrialLog in
Avatar of gigifarrow
gigifarrow

asked on

Lookup in a text box trying to sum it.

I have a query called qrytemple.

In the query I have a field called Percentage.
It calculates precentage for each record.

I am not getting no error Messages.
I am using a text box for the following code:

=DLookUp("[Percentage]","qrytemple"," [Unit ]= ('278th ABCT')")
I need a total for all the percentages from each unit.
 (and this code  is just counting the first record)

I also need a over all total.
My code looks like this and it works:
=DLookUp("[Percentage]","qrytemple")(this is also only adding the first record)



How do I get these two codes to sum?
HelpDlookUp.zip
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

You'll need to provide a better explanation. I can't understand what you mean by:

"I need a total for all the percentages from each unit."

Can you show some sample data of what you're looking for? The way I read this, the following DSum would work:

DSum("Percentage", "qryTemple")

That would add together all values in the Percentage column in the qryTemple query.

By the way, your attached database has 0 values in the Percentage column, so you'll only get 0 Sum values, obviously.
Avatar of gigifarrow
gigifarrow

ASKER

In the sample database there is a  table called tblTempleFacilityFullup.  Yes ,it is 0 amount in that field but the whole field name is percentage complete and that is not the field Im talking about.

In the sample database there is a query called qryTemple. In that query there is a calculation called "Percentage" that is the field Im talking about. It does a calculation..

It totals the value of each field that has a percentage and divides by 100 to give you the toatal percentage for each military unit.

In the table there is a field called units that is a name of  a company in the military.

This code does not work get ?Name error Message.
DSum("Percentage", "qryTemple")
 When I try Dsum with a query I get a error

However when I use Lookup I dont get an error. I just dont get the right totals which is based on the query in the sample datbase. There are percentages there in those records in the query..



My code is only giving me the first record in the query Percentage as the answer to both of my calculatioms..

Using the lookup is not calulating what I need.



Example

=DLookUp("[Percentage]","qrytemple")(this is also only adding the first record) need total of all the units in the military.

=DLookUp("[Percentage]","qrytemple")(this is also only adding the first record)

(this is also only adding the first record and I  need total of  each unit separarely).

On the form I have a text field called total for all units and another total for each military unit.
SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Jeff!!!! I will try that. Just to let you know I was asked to convert a excel spreadsheet with lots of formulas to Access. This is part of it.

Just when I think I am finished they ask me to do something else.lol  But Im getting better, especially with a lot of your help!!!!
Wow!! LSM thats alot of work I will also try that and see what will work best.
Thanks for your help and time!!!!
I think if the user could like instead of checking the step that they  could input what the percentage the step was worth. That would be so much easier. But too much trouble for the user.
Gig,

No points wanted for me.
I am sure LSM can get you sorted without my comment.

I only thought to mentioned it as a "FWIW"...

;-)

Jeff
Not really that much work. You just build a few queries you can use with qryTemple.
Okay I tried to make another query from the query that is in the record source of the form called frimTempleFullup. but when I go to the query wizard that query doesnt show up. And I dont know how to make it show up. Or even change the name. I really would like to just use that query since I already have that field in my form. Can you tell me how to do that?


Since I didnt know how to do that:
 I  made another query called qryTemple. And put a field called Percentage and used the code from the query in the record source in the from (the field called  Percentages)

I then made a query called qryTempletotal out of the query called qryTemple
I put a field to sum percentages called  Total: Sum([Percentage]).

 I get an error." You tried to execute a query that does not include the specified expression 'Production' as part of an aggregate funtion. "
MODKitProduction.zip
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay I will try this but why cant i Just use my second query that I created and do all the calculations from my text boxes as I was asking in my first question?


Queries cant caculate in a text box?

=DLookUp("[Percentage]","qrytemple"," [Unit ]= ('278th ABCT')")
I need a total for all the percentages from each unit.
 (and this code  is just counting the first record)

I also need a over all total.
My code looks like this and it works:
=DLookUp("[Percentage]","qrytemple")(this is also only adding the first record)



How do I get these two codes to sum?
but why cant i Just use my second query that I created and do all the calculations from my text boxes as I was asking in my first question?
You could perhaps do that, but you'd want to use DSum instead of DLookup.

I don't know what you mean by "How do I get these two codes to sum?". What are the "two codes", and how would they sum?