Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Calculate Values
Walter Hamilton 
    
5 years ago
I have linked tables for Prime Contracts, SubContracts, and ChargeCodes.  I need to create a query that shows a list of SubContracts and the Total Value of all the ChargeCodes associated with each SubContract.  I've been able to get DSUM to work if I manually put the SubContractID in the expression but I can't get it to work with referencing the SubContract_ID field.

My current expression that works is:

=DSum("[Total Value]","[qry_SubContract_ChargeCode_Values]","[SubContract_ID]=2")
Scott Axton  @Reply  
        
5 years ago
How did you enter it?  Try:

=DSum("[Total Value]","[qry_SubContract_ChargeCode_Values]","[SubContract_ID]=" & [SubContract_ID])
Scott Axton  @Reply  
        
5 years ago
I just re-read the question and I think you are trying to subtotal the subcontract by Prime Contract.  Correct?

I need to rethink this one when I'm not half asleep.
Alex Hedley  @Reply  
           
5 years ago
What data type is SubContract_ID? Number or Text?
Walter Hamilton OP  @Reply  
    
5 years ago
Scott,

That worked.  Thank you!
Walter Hamilton OP  @Reply  
    
5 years ago
The above expression worked but now I can't get it to display as currency.  I'm unable to select a format for the Text Box on the Form Property sheet.
Adam Schwanz  @Reply  
           
5 years ago
Try using CCur to convert it to currency
CCur(stuff)
Scott Axton  @Reply  
        
5 years ago
Formats in queries can sometimes be finicky.  
In your query where you have the DSum surround it with the Format function.

=Format(DSum("[Total Value]","[qry_SubContract_ChargeCode_Values]","[SubContract_ID]=" & [SubContract_ID]), "Currency")

Sometimes format in a query won't "stick".
You will probably have to format the display field in your form.  Is it a continuous form or a single form?
Walter Hamilton OP  @Reply  
    
5 years ago
Scott,

That worked great.

I now need to limit it based off another column [PoP End].  It needs to only use values when [PoP End] is >=Date()
Scott Axton  @Reply  
        
5 years ago
Sounds good to me.  Just add it to your query.
Walter Hamilton OP  @Reply  
    
5 years ago
Scott,

I was having issues with doing everything in the same query.  I built a new query and I'm grabbing the values from [tbl_ChargeCodes] instead of another query.  my current expression without the Date() criteria is:

Cumulative Invoiced: Format(DSum("[Cumulative Invoiced]","[tbl_ChargeCodes]","[SubContract_ID]=" & [SubContracts_ID]), "Currency")

This expression works, but I need to not include the values from records who's [PoP End] has passed.

I'm using the following expression but it's returning #Error:

Cumulative Invoiced: Format(DSum("[Cumulative Invoiced]","[tbl_ChargeCodes]","[SubContract_ID]=" & [SubContracts_ID] & "' AND [tbl_ChargeCodes].[PoP End]>=" & Date()), "Currency")
Scott Axton  @Reply  
        
5 years ago
Walt -
The  [tbl_ChargeCodes].[PoP End]>=" & Date() should be in the query criteria.  Not in the formula for summing the subcontracts.
If that doesn't make sense take a screen shot of your query in design mode and post it using the Upload Images in the first post of this thread.
Walter Hamilton OP  @Reply  
    
5 years ago
Scott,

My brain wasn't thinking the correct way.  That works.  I really appreciate the assistance.
Scott Axton  @Reply  
        
5 years ago
You get to where you can't see the forest for the trees some times.  The more you fix things the quicker you see it in the future.

Glad that helped.  
Walter Hamilton OP  @Reply  
    
5 years ago
I've encountered another issue with this.

I'm on a form with comboboxes for:

Major Command
Component Command
Command

I've created text boxes beside each of these to display the Total Value, Funded Amount, Invoiced Amount, and Burn Rate.

I'm using the following example as the expression for the Total Value beside Major Command:

=Format(Nz(DSum("[Total Value]","[qry_Major Command Values]","[Major Command_ID]=" & [Combo33]),0),"Currency")

I have #Error in each field prior to selecting something in the Combo Box.  Once I make a selection everything works as desired.  I that the Nz() would fix that?
Adam Schwanz  @Reply  
           
5 years ago
That error is because your telling it to search for a value, and then not even giving it the value to search for (the combo box selection). NZ is for if there is a value, but it is blank/null, then it will let you put a value in. You'll need to use an if then statement or IIF on this too.
Adam Schwanz  @Reply  
           
5 years ago
Alternatively, you could just throw the code that sets the fields into the after update event of the combo box. Then they'd be blank when you don't have a choice, and when you change the combo box it would update.
Juan C Rivera  @Reply  
             
5 years ago
Oh wow I wish I followed this one from the begining
if posible I like to see the end product, I work for the Goverment and do this all the time on service contracts.  IDIQ and JOC.
Always can use a fresh look on how things are done.

V/r
Juan
Walter Hamilton OP  @Reply  
    
5 years ago
Adam,

That worked but it created a new problem.  When I filter something that doesn't have an associated record I the code throws an error for my [Burn Rate] text box.  the code I'm using is:

Text57.Value = IIf([Text56] = 0, 0, [Text56] / [Text55])

Adam Schwanz  @Reply  
           
5 years ago
One thing after another :). If you're using that in an event try this

If Text56 = 0 or Text56 = Null or Text56 = "" Then
Text57 = 0
Else
Text57 = Text56/Text55
End If
Walter Hamilton OP  @Reply  
    
5 years ago
Adam,

Thanks again.  I ended up having to put the following in the Control Source for the Text box for it to work:

=IIf([Text45]=0 Or [Text47]=0 Or [Text49]=0,0,[Text49]/[Text47])
Alex Hedley  @Reply  
           
5 years ago
I hope these textboxes are getting descriptive names soon :)
Scott Axton  @Reply  
        
5 years ago
You go Alex!
FWIW - I do wish it was easier to do it when you are adding it to the forms in the first place.
Alex Hedley  @Reply  
           
5 years ago
I can't blame you if the teacher doesn't :p
Scott Axton  @Reply  
        
5 years ago
Alex you still can't blame me. :-) Not my code.
That's one of my peeves too.  Just a PITA to do some times.
Walter Hamilton OP  @Reply  
    
5 years ago
Alex,

Yes.  I'll fix it soon.  I'm learning as I go.
Richard Rost  @Reply  
          
5 years ago
Hey hey... don't yell at the teacher. The only thing I USED to say didn't need descriptive names was command buttons, and even then I turned around and changed my stance after Alex talked me into it.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/2/2026 7:22:06 AM. PLT: 1s