Is Textbox.Dirty a thing? (1 Viewer)

JMongi

Active member
Local time
Today, 11:53
Joined
Jan 6, 2021
Messages
802
This may be a moot point as what I want to accomplish may be achieved by other means. But...

The code I am modifying has an unbound textbox that usually runs some code in the AfterUpdate() event after the user presses "Enter" to update the textbox.
I want to shift all the code into a command button event(s) and am curious as to how Access handles the data in the unbound textbox as it's being entered. Doing a little Googling and searching in MS knowledge base led me to the idea of a Textbox.Dirty property. However, MS example code in their entry talking about Textbox.Dirty is all about the form being dirty and doesn't actually use textbox.dirty AT ALL. Go figure.

So, is Textbox.Dirty a thing? Does it matter with no control source? Can I just read the unupdated textbox value entered by the user (without an "enter" press)? Can I simulate/execute an "enter" press on the textbox based on the click event? In general that is frowned upon, but perhaps this is one of the exceptions to the rule?

Sorry, a little rambly today (just today?! :p)
 

Isaac

Lifelong Learner
Local time
Today, 08:53
Joined
Mar 14, 2017
Messages
8,738
What about just using the .Change event, and refer to the .Text property of the textbox? Would that work? I don't believe Textboxes have a Dirty property?
 

JMongi

Active member
Local time
Today, 11:53
Joined
Jan 6, 2021
Messages
802
Just as proof that I'm not crazy

Well, at least because of this...Ha!
@Isaac - I presume that each character entry in the textbox fires a .change event? I need the trigger to be user initiated. Related to my other threads, this is using a login form. The expected functionality of a login form is to enter your UN/PW and then click "Log-In" or that pressing "Enter" is the same as clicking "Log-In". So, I need to avoid triggering the event after every character entry.
 

JMongi

Active member
Local time
Today, 11:53
Joined
Jan 6, 2021
Messages
802
So, I know that even on an unbound textbox that pressing the "Enter" key triggers the update and writes the entered value into the textbox.value spot. The question is, can I pull the current temporary editing of the textbox without updating it? Is that the .text property? Is that continuously updated? I tried searching for that in the MS knowledgebase but am not getting any hits for Access VBA
 

Isaac

Lifelong Learner
Local time
Today, 08:53
Joined
Mar 14, 2017
Messages
8,738
Oh, good call. I've never used that. Only for bound controls, yes. Yes, each character change fires the Change event.
So what is it you actually need to do - I mean I saw your additional explanation, but can't see how that ties to a textbox dirty event.
 

Isaac

Lifelong Learner
Local time
Today, 08:53
Joined
Mar 14, 2017
Messages
8,738
The question is, can I pull the current temporary editing of the textbox without updating it? Is that the .text property? Is that continuously updated?
The Change event fires once for every character of text changed. Yes, refer to .Text property.
 

JMongi

Active member
Local time
Today, 11:53
Joined
Jan 6, 2021
Messages
802
Sorry if I'm overcomplicating it. If .text functions as you say that will be perfect. Do you have a reference source for that? As I said, I can't seem to track anything down in MS knowledgebase.

The idea is that the user clicking on "Log-In" implicity says that they are done entering the values so I would be comfortable pulling textbox.text at that point.
 

JMongi

Active member
Local time
Today, 11:53
Joined
Jan 6, 2021
Messages
802
What lousy search. I specifically typed in "TextBox.Text property (Access)" [I can figure out their standardization...] and didn't get that to come up. *sigh* Thanks! This should get me down the path. If I run into a snag I'll post more.
 

Isaac

Lifelong Learner
Local time
Today, 08:53
Joined
Mar 14, 2017
Messages
8,738
What lousy search. I specifically typed in "TextBox.Text property (Access)" [I can figure out their standardization...] and didn't get that to come up. *sigh* Thanks! This should get me down the path. If I run into a snag I'll post more.
I guess I got lucky what I tried was something like: "Access form textbox .Text property" FWIW
I hear ya - FWIW I use google too. Some dude tried to get me into Bing and I tried it for a few days , just couldn't do it any more
 

JMongi

Active member
Local time
Today, 11:53
Joined
Jan 6, 2021
Messages
802
Hmm...if I'm reading this correctly...

.text is the current temporary value as its being entered while the control has focus.
By clicking on the "Log-In" command button, that focus should shift to the "Log-In" button.
Thus .text should be written to .value before the Click Event of the button.
Thus I should be able to use textbox.value anyway as its been automatically updated.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 10:53
Joined
Feb 28, 2001
Messages
27,005
OK, first part... the control.TEXT property is ONLY available for the control currently in focus. Second part... the article you referenced shows that the textbox.Dirty property is only available for bound forms. It doesn't specify whether it makes a difference that the form is bound but the individual control is not. I am going to suggest that you go into form design mode to see whether that unbound control's properties include ".Dirty" - because I suspect it will not.

When I had to test whether an unbound control had changed, I made it a point to have a variable to hold the last recorded value of the control so that I could do the comparison on the .LostFocus event. Of course if there HAD been a change, the last act of the routine was to update that "place holder" variable.
 

JMongi

Active member
Local time
Today, 11:53
Joined
Jan 6, 2021
Messages
802
@Isaac - Brilliant! And now I have a better understanding of the data process for an individual control. That's handy.
@The_Doc_Man - Interesting about the bound form thing. There is an "OnDirty" event with my unbound textbox but that's not exactly the same thing. I can see your point about the temporal nature of control.text. In this application, it's not a concern because I'm not worried about anything before or after. Of course, because of that, I don't even need to use control.text.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:53
Joined
May 21, 2018
Messages
8,463
This may help. I tried to capture the important related values so you can see this work along with some of the events


1 Enter.jpg

1. As you enter the form the value of the control equals the text property, value, old value, and the underlying table value. The form is not dirty


2. Change.jpg

2. As you change the value the text property changes but the value, old value, and control source value remain unchanged. What is interesting the form's ondirty event fires then the control's ondirty fires. However the on dirty property does not update until after both of these events fire. Both of these events fire before the change event (seems weird).

3. Exit.jpg


3. Exiting the control causes the value property to update to the text property. Notice the Oldvalue and the control source have still not changed. Nothing has been committed to the table.

4. Save.jpg


4. Clicking the button would be the same as moving to a new record and thus saving the record. This is the same as an after update. Oldvalue gets changed to the current value and the record is committed to the table

I should have shown the before update. When the before update fires the oldvalue has not yet been updated and the record is not committed to the table. This is why you can cancel. When you cancel you stop the value from being saved to the table. If you undo it then replaces the new value with the old value allowing you to "roll back"
 

Attachments

  • Dirty.accdb
    1.4 MB · Views: 318

JMongi

Active member
Local time
Today, 11:53
Joined
Jan 6, 2021
Messages
802
@MajP - Thanks for the extra examples! That's good to know. I don't have too much need at the moment for that type of granular control but I'm betting I will in the future. That will help me make sure I manage the data properly.
 

Users who are viewing this thread

Top Bottom