Results 1 to 8 of 8
  1. #1
    Niko is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    47

    Code for calculating nettweight and loss

    Hi all, I have an issue with my form for my "nettweight" and "loss" textbox which keep showing #type! on my textbox after i click on "Clear" on my textbox. I realize that it is because i use these two textbox control source for calculation. Hence, once i removed the calculation in the control source, the #type! on my textbox was gone.

    I would like to know how to write code so that when the form load together with all the data or when user click on 'next" for the next record set, it will automatically show the nettweight.
    Formula: pounds/2.2

    Next, i would like the code to work in the same way for the loss as well, when user key in the grossweight the loss will automatically be calculated and show in the loss textbox.



    I have also attached my database above.

    Thankyou! Have a good day
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Can't 'clear' a textbox with an expression. Can't set Value when there is an expression in the ControlSource.

    It shows #Type! error because code is setting Pound and Grossweight textboxes to an empty string and can't do arithmetic with an empty string. Set the Pound and Grossweight controls to Null instead.
    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
    Niko is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    47
    Quote Originally Posted by June7 View Post
    Can't 'clear' a textbox with an expression. Can't set Value when there is an expression in the ControlSource.

    It shows #Type! error because code is setting Pound and Grossweight textboxes to an empty string and can't do arithmetic with an empty string. Set the Pound and Grossweight controls to Null instead.
    Yup, i know. thats why i will need to find a way to include the calculation. Hence, i am thinking of using VBA code to do that? I tried before update but it does not seem to be working.
    Do you have any idea?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Remove the code that tries to set value of Netweight and Loss. Instead of setting Pound and Grossweight to empty string, set to Null.
    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
    Niko is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    47
    Quote Originally Posted by June7 View Post
    Remove the code that tries to set value of Netweight and Loss. Instead of setting Pound and Grossweight to empty string, set to Null.
    what is the reason behind by setting pound and grossweight to null?

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    @Niko,

    Please stick with one thread......
    earlier thread https://www.accessforums.net/showthread.php?t=68484

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Set to Null so the expression is not attempting arithmetic calculation with empty string resulting in the error. Arithmetic calculation with Null will return Null, no error.
    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.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    Quote Originally Posted by June7 View Post
    Set to Null so the expression is not attempting arithmetic calculation with empty string resulting in the error. Arithmetic calculation with Null will return Null, no error.
    Too bad I didn't see this before wasting so much time elsewhere.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 8
    Last Post: 05-27-2016, 02:57 PM
  2. Calculating % in VBA Code For Excel
    By mkc80 in forum Access
    Replies: 1
    Last Post: 09-16-2012, 05:39 PM
  3. Replies: 3
    Last Post: 08-17-2012, 02:01 PM
  4. Code for calculating employees overtime pay
    By Nixx1401 in forum Access
    Replies: 17
    Last Post: 05-05-2011, 05:13 PM
  5. data loss
    By Binu in forum Access
    Replies: 1
    Last Post: 07-21-2010, 05:14 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