Detect Textbox Change by User but not by Software code

Posted on 2006-04-19
Last Modified: 2010-05-01
I know you can use _LostFocus and _Change methods to detect when a text box has changed.  In my case, if a certain situation exists, I want to pop-up a message to the user.  The problem is if I put that pop-up in _LostFocus or _Change it happens too much at random times as that value may be "changed" by software code.  

How do I detect that the user really tried to change the value?  But EXCLUDE all cases where the value is changed by code?

This is an urgent item for me as I have to do a release today.
Question by:torrid333
    LVL 6

    Accepted Solution

    Have you tried to use the keypress event of the textbox, as only the user is going to press keys!
    LVL 14

    Assisted Solution


    Don't try to move in different event, it's _Change you need to code.
    But there a public variable "codechange As Boolean" and in textbox_Change this line:
    If codechange Then Exit Sub

    Need to set this variable true just before you program executes code which will change text in that textbox, and set it false again when the changes are made.


    Author Comment

    The trick is really to do something a combo of cubixSoftware and Matti's suggestions...

    I used a boolean in KeyPress to indicate that text is "dirty"... that the user has actually tried to change the value... and then in LostFocus it is checking that dirty flag to determine whether to pop up the user message.  That flag is then cleared after showing the message.

    cubix... if you just put the message in KeyPress then it will try to pop up the message every time they hit a key.  This leads to too many pop-ups.

    Matti... the code changes this value in lots of places... very inconvenient to set that boolean everywhere in code.  Plus, a year from now it may be forgotten and then voila new bug appears adding new unneeded msg pop-ups.

    I guess I solved my own problem... thanks for responding though.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now