Results 1 to 13 of 13
  1. #1
    mechanicalscarecrow is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Posts
    9

    SubTotaling on a Form with multiple Sub Forms

    Hello everyone, I am new to access and am trying to create a database to help create invoices. The form and subforms are based on queries which are based on tables. The two subforms are to separate taxable products with non-taxable products. I have followed this link: http://www.ms-access2010.com/tutorials/forms2.html to create it, only using the two subforms instead of one.



    The issue is, not every invoice has both non-taxable and taxable products. Most have one or the other, however the equations only work when I have both. I have tried multiple different options, but have yet to find the correct way to do it.

    Here's what I have tried.

    =[TaxDetailSubF].[Form]![SubTot]+[NonTaxableDetailF].[Form]![SubTot2] This code has given me a #Type! error in the invoices that do not have both.

    =Nz([TaxDetailSubF].[Form]![SubTot],0)+Nz([NonTaxableDetailF].[Form]![SubTot2],0) This has given me a #Size! error

    =Nnz([TaxDetailSubF].[Form]![SubTot],0)+Nnz([NonTaxableDetailF].[Form]![SubTot2],0) This has given me a #Name? error.

    If you need anymore information on my database please let me know. I've been trying to figure out this problem for a few days now. Odds are, it's probably an easy fix, I'm just missing it.

    Thank you for your help!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Did you place the Nnz() custom function in a general module?

    I tested the Nnz() function and cannot replicate the issue. Must be something about your form design. If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    mechanicalscarecrow is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Posts
    9
    I didn't put it in a module I don't think. Do I need to? I've been placing all of my equations in the Control Source on the Property Sheet for the field that I want it to appear in. How would I go about putting it in a module.

    Thank you!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Where did you learn about Nnz()? It is a custom user defined function - VBA code - whereas Nz() is an intrinsic function.

    http://access.mvps.org/access/forms/frm0022.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    mechanicalscarecrow is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Posts
    9
    It was actually on this forum that I learned about Nnz() I believe. I was researching my problem and someone had pretty much the exact same situation. However, I could not follow exactly how it was solved.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Put the Nnz() function code into a general module so it can be called from anywhere, including queries.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    mechanicalscarecrow is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Posts
    9
    Ok! I have one more questions, and I apologize because it is probably a very basic concept. How do I call it to the form I want to use it in?

    Thank you so much for all the help you have been doing!

  8. #8
    mechanicalscarecrow is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Posts
    9
    'This code was originally written by Keri Hardwick. 'It is not to be altered or distributed, 'except as part of an application. 'You are free to use it in any application, 'provided the copyright notice is left unchanged.''Code Courtesy of'Keri Hardwick'
    Function nnz(testvalue As Variant) As Variant
    'Not Numeric return zero
    If Not (IsNumeric(testvalue)) Then
    nnz = 0
    Else
    nnz = testvalue
    End If
    End Function

    Also, above is the code that I was referring to earlier. Is it fine as is and I can copy and paste it into the module?
    Thanks again!

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Code looks fine to me. Paste it into a general module.

    Call it from query or textbox ControlSource (as shown in your OP).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    mechanicalscarecrow is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Posts
    9
    I am confused as to how to call it in. I've called the module TestModule and in the expression builder for the Control Source of the text box I have tried to put in =[TestModule], to which I get a #Name? error.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Call the function, not the module. Like the attempt you posted in first post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    mechanicalscarecrow is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Posts
    9
    When I do that, it pops up saying: The expression entered has a function containing the wrong number of arguments.

    =Nnz([TaxDetailSubF].[Form]![SubTot],0)+Nnz([NonTaxableDetailF].[Form]![SubTot2],0)

    I'm sorry for all the trouble this is becoming. Thank you for all of your help!

  13. #13
    mechanicalscarecrow is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2015
    Posts
    9
    Oh wait! I took out the ,0 from each one and It works! Thank you!!!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-05-2015, 07:50 PM
  2. Multiple Sub-Forms in a main form for editing
    By Harley Guy in forum Forms
    Replies: 1
    Last Post: 12-19-2013, 12:54 PM
  3. multiple tables, multiple forms, one record
    By FullyBaked in forum Forms
    Replies: 7
    Last Post: 10-24-2011, 04:27 AM
  4. Multiple forms or embedded sub-forms
    By Juicejam in forum Forms
    Replies: 2
    Last Post: 08-23-2011, 07:31 AM
  5. Sorting/Subtotaling pivot tables
    By Tina in forum Access
    Replies: 0
    Last Post: 08-25-2010, 10:34 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums