Results 1 to 8 of 8
  1. #1
    VarunJain is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Nov 2016
    Posts
    1

    Microsoft Access SUM #Error

    I have an access form and subform that i created using a query. Then, through design view, I created a text box, and entered a rather long nested iif that referred to other fields in the subform.

    Now, I want to use the SUM function to add up the values (results of iff) in the created text boxes, each which have different values. I have tried everything I can think of, but it always comes up with #Error! no matter what I do.

    Can anyone help me with this?


  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2013
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Are the results of your IIF statement actually numbers or are they text that look like numbers, or are any of the text box results of the IIF statement actually null or empty?

    If the former, then you need to change the results to numbers, and if the latter, then you may need to employ the NZ function into your calculations.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Also, you cannot use an Aggregate Function against a calculated Field, which I think is what you have using your IIFs...you have to use them directly against the calculated expression itself. I won't attempt that, using nested IIFs (which are frequently troublesome,) but here's a simple example of the concept:

    If

    C = A + B

    you cannot use

    SUM(C)

    but have to use

    SUM(A + B)

    But given how problematic nested IIFs can be, in addition to the questions posed by alansidman, you need to make sure that you're actually getting the results from the IIFs that you expect.

    Linq ;0)>

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    if you're using something like:
    dim mytotal as long
    mytotal = sum(t1 +t2 +t3)

    That won't work. Sum is not a vba function. You can use it in sql but not in vba.

    The above should simply be
    mytotal = t1 + t2 + t3

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    Once you figure out if there are text values or nulls involved (and deal with them if there are) you might want to use the DSum function over the query or table records that the form contains. Look here for info on using that function (see Domain Aggregate Functions). You'd put the function in your calculated control - unless you're stuck with a bunch of messy IIF's.
    https://www.techonthenet.com/access/functions/
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Apparently not a pressing problem...since we haven't heard from the OP in 10 days!

  7. #7
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2013
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Apparently not a pressing problem...since we haven't heard from the OP in 10 days!
    or one of our answers triggered a solution and the OP does not care nor wish to acknowledge.

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Be nice to know, wouldn't it?

    BTW, love your avatar!

    Linq ;0)>

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

Similar Threads

  1. Replies: 2
    Last Post: 04-22-2016, 10:54 PM
  2. How to stop Microsoft Access Error 3817?
    By SwenGyrowetz in forum Database Design
    Replies: 4
    Last Post: 07-27-2015, 04:28 AM
  3. Need to Circumvent general Microsoft Access Error?
    By Heatshiver in forum Programming
    Replies: 1
    Last Post: 05-09-2012, 06:41 AM
  4. Microsoft Access Error 3071
    By Ev0luTioN in forum Access
    Replies: 1
    Last Post: 08-04-2010, 04:35 PM
  5. Replies: 1
    Last Post: 03-02-2010, 03:01 AM

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