Results 1 to 4 of 4
  1. #1
    Skarvion is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    13

    Interdependable Text Box

    Hi, this is my first post in this forum, looking forward getting to know more about access.

    So I've made a form for transaction. Say there's a Price textboxt that shows the price of the selected item from another combo box. And then there are 2 textboxes for discount, a PercentDiscount textbox that allow the user to deduct the price in percentage form and the FixedDiscount that allows them to deduct in a fixed number.
    These 2 discount textboxes dependent on each other. For example if the price is $100, then when the PercentageDiscount is 10%, the fixed discount is automatically shows $10 and vice versa.

    Although I did managed it to work with VBA using LostFocus event in each of the textboxes, it's not foolproof. If for example the Price of the item in question is changed from the combo box, the discount textboxes stays the same.



    Is there any workaround for this to gurantee the discount is always updated? Thanks in advance

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You need a Function that updates all of the TextBoxes and then call this function from the After Update event of all of the TextBoxes.

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,840
    in your percentdiscount control after update event you put

    me.fixeddiscount=me.PercentDiscount*price

    in your fixeddiscount control after update event you put

    me.PercentDiscount=me.fixeddiscount/price

    in your price control after update event you put

    percentdiscount_afterupdate

    which will recalculate the fixed discount. If on the other hand you want the fixed discount to remain the same and recalculate the percentage (clearly you can only do one or the other) you put

    fixeddiscount_afterupdate

    calling the sub just means you are reusing the code - if at some point in the future you wanted to change the calculation, you only have to do it in one place

  4. #4
    Skarvion is offline Novice
    Windows 10 Access 2013
    Join Date
    Jan 2016
    Posts
    13
    Quote Originally Posted by Ajax View Post
    in your percentdiscount control after update event you put

    me.fixeddiscount=me.PercentDiscount*price

    in your fixeddiscount control after update event you put

    me.PercentDiscount=me.fixeddiscount/price

    in your price control after update event you put

    percentdiscount_afterupdate

    which will recalculate the fixed discount. If on the other hand you want the fixed discount to remain the same and recalculate the percentage (clearly you can only do one or the other) you put

    fixeddiscount_afterupdate

    calling the sub just means you are reusing the code - if at some point in the future you wanted to change the calculation, you only have to do it in one place
    Hi Ajax, thanks for the reply. It worked perfectly.

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

Similar Threads

  1. Replies: 7
    Last Post: 06-05-2015, 11:13 AM
  2. Replies: 2
    Last Post: 07-09-2014, 12:43 PM
  3. Replies: 9
    Last Post: 04-18-2014, 08:51 PM
  4. Replies: 3
    Last Post: 02-07-2013, 09:53 PM
  5. Replies: 1
    Last Post: 05-24-2012, 04:59 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