Results 1 to 7 of 7
  1. #1
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44

    Formula to calculate textboxes - Form view

    Hello, I have a small problem with calculating the sum od 6 textboxes.

    Click image for larger version. 

Name:	Capture.JPG 
Views:	19 
Size:	26.7 KB 
ID:	43979



    There are six textboxes named kg_1. kg_2. kg_3. ... (shown on the picture), default value 0, and set format "#,###" so that zero is not visible in form view.
    Last textbox "ukupno_cig" is calculated field with formula "([kg_1]+[kg_2]+[kg_3]+[kg_4]+[kg_5]+[kg_6])" and when you enter the numbers in one six fields it automatically calculates the sum in he field "ukupno_cig". But when you delete numbers from one field, the textbox for sum is left blank. How can I fix that?
    Click image for larger version. 

Name:	2.JPG 
Views:	18 
Size:	12.5 KB 
ID:	43980

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi

    Use the NZ as shown:-

    Nz([kg_1],0)+Nz([kg_2],0)+Nz([kg_3],0)+Nz([kg_4],0)+Nz([kg_5],0)+Nz([kg_6],0)

    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  3. #3
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Quote Originally Posted by mike60smart View Post
    Hi

    Use the NZ as shown:-

    Nz([kg_1],0)+Nz([kg_2],0)+Nz([kg_3],0)+Nz([kg_4],0)+Nz([kg_5],0)+Nz([kg_6],0)

    Tried that in calculated field, returns this error


    Click image for larger version. 

Name:	Capture.JPG 
Views:	18 
Size:	46.0 KB 
ID:	43981

    Where should I put that formula you wrote?

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Everyone should make the function: NZZ()
    Code:
    function Nzz(byval pvVal)
    on error résumé next
    NZZ=Nz(pvVal,0)
    End function
    Save a lot of typing in queries.

  5. #5
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    You should not be using calculated fields in the table.

    Calculations are usually carried out in queries that Forms are based on.

    You would then create a Field in the Query to make your calculation.

    Can you upload a zipped copy of the Db ?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    This is a fundamental design problem.

    You should have (possibly child) records that are individual weights.
    These would then be very straight forward to add up.

    What happens when you need KG_7 ? Answer: you have to redesign your whole database to accommodate it.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Thank you all for your advices.
    I tried to put the function NZZ in user functions and I also tried that formula in control source of texbox and it works, but then it doesn't save the calculated number in the table, it only shows on the form view.
    Sorry for being a noob, still in learning process

    Click image for larger version. 

Name:	Capture.JPG 
Views:	11 
Size:	32.7 KB 
ID:	43993

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

Similar Threads

  1. Replies: 6
    Last Post: 05-10-2018, 10:55 AM
  2. Replies: 1
    Last Post: 01-21-2016, 04:56 PM
  3. Replies: 3
    Last Post: 10-09-2014, 03:31 PM
  4. Replies: 1
    Last Post: 09-04-2013, 08:57 AM
  5. Need a formula to Calculate Date Ranges
    By nagiese in forum Queries
    Replies: 5
    Last Post: 07-12-2013, 01:53 PM

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