Results 1 to 5 of 5

Code won't run on change event

  1. #1
    achammar is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2019

    Code won't run on change event

    So I only somewhat know Access just FYI... I have a textbox on a subform in Datasheet view. It's control source is a calculated field in a table. When the calculation is made or the values change to that changes the value in table, the text box changes to match as it should. But when it changes, the code in the change event does not run. Can someone tell me why? Does that event require a manual change to the text box or what? And how can I get the code to run when it changes on it's own?

    Thank you very much!

  2. #2
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    UK - Wiltshire
    As a general rule events aren't triggered by other events, so your code won't be called.

    If either of your values driving your calculation are changed use that to trigger the change.
    DLookup Syntax and others
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    the CHANGE event is for humans. It wont fire via code.
    If you want it to fire, put it in the code on the box that gets changed.
    (dont use change, use AFTERUPDATE event)

    if txtBox1 is changed by user then refresh the calc box:
    sub txtBox1_Afterupdate()
    end sub

  4. #4
    achammar is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2019
    Thank you both! I had just tried what you both suggested when I read your posts although I wanted to use the calculated box, mainly so I could have the code in only 1 control event instead of 2, but I now know it doesn't work that way... which is no biggie.. it works absolutely perfectly doing it this way! I first used the LostFocus event and it worked fine but changed it to AfterUpdate after reading these posts. I believe that is better. It's all working very good now! Thank you so much for clarifying this up for me!
    So I'm new here.. this is only my second post. I see I can add to your reputations but not sure if there's anything else I need to do to close this, or accept 1 as an answer or what.. although you both gave me the same answer. I will add to your reputations, but if there's something else I need to do, please tell me. I very much appreciate your help more than you know!

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Ontario, Canada
    Everything you could want to know is here, if you are good at searching. You can search on a term, but if you know what object the event/method/property applies to, you start with that since this is an object oriented model. I find that brings up less fluff.

    In your case, you're working with an Access textbox, so you navigate to Access > Object Model > Textbox > Events and find On Change. There you will see that the event isn't triggered by code. LOTSA info - I go there often.
    - "doesn't work" is no help. Post err msgs and where.
    - Use code tags for code/sql. Implement changes in copies of your database.
    Sometimes I talk to myself - like when I need expert advice.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-24-2018, 09:37 AM
  2. on change event
    By angie in forum Access
    Replies: 1
    Last Post: 04-03-2018, 11:27 AM
  3. update/on change event
    By Homegrownandy in forum Access
    Replies: 5
    Last Post: 07-06-2017, 06:57 AM
  4. Using Event Code to Disable another Event Code
    By mortonsafari in forum Forms
    Replies: 1
    Last Post: 08-29-2016, 11:09 PM
  5. Replies: 7
    Last Post: 05-28-2013, 09:11 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
Tech Forums: Microsoft Office Forums