Results 1 to 9 of 9
  1. #1
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171

    VB codes in form for Total


    Hello,
    I have two unbound text boxes 1 and 2 in a form.
    I want to get the sum of these two in third text box.
    I need vb coding for this.Thanks

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    No VBA necessary.
    In the Control Source property of your 3rd Text Box, simply use an equation like this:
    =Val([TextBox1]) + Val([TextBox2])

  3. #3
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    Thanks.
    I know this procedure but I just want to know in VBA.

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Pretty straightforward:
    Code:
        Me.TextBox3 = Me.TextBox1 + Me.TextBox2
    You will just need to attach this code to some "event", maybe in the "AfterUpdate" event of the second Text Box, or maybe on the click of a command button.

  5. #5
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    I tried this code in after update event of text2 but result is not correct.
    I put 2 in text1 and 2 in text2 but instead of result 4 its showing 22 in result.

  6. #6
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Did you update the Format property of your Text Boxes to a numeric option, like Fixed?

  7. #7
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    yes working now.Thanks
    I was trying text3.text = text1.text+text2.text
    but it was not working.

  8. #8
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    The ".text" part tells it to return a text value, and not a numeric value. In that case, the "+" works as a "text concatenater" instead of a "numerical adder".
    Also, without formatting the text box first, I think the default is to treat it as text also, which is why we want to explicitly format it numerically.

  9. #9
    glen is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    171
    Thanks for explanation.

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

Similar Threads

  1. Calculating distance between 2 zip codes
    By crowegreg in forum Programming
    Replies: 7
    Last Post: 06-13-2016, 07:20 PM
  2. Help Needed in Login Form Codes
    By Nashaath in forum Access
    Replies: 19
    Last Post: 05-14-2012, 06:52 AM
  3. Queries and codes
    By alliandrina in forum Queries
    Replies: 2
    Last Post: 05-03-2012, 05:53 PM
  4. Consolidation codes from different table.
    By suverman in forum Queries
    Replies: 3
    Last Post: 05-13-2011, 10:39 AM
  5. Zip Codes
    By Laurie B. in forum Access
    Replies: 6
    Last Post: 02-25-2011, 02:38 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