- Local time
- Today, 16:09
- Joined
- Feb 28, 2001
- Messages
- 27,175
First, let me put this in perspective: :banghead:
OK, now that we have that out of the way, my question is really whether anyone has ever seen this before.
Ac2007 database. My form has a bound text-box to a text-type underlying field in a Dynaset query to a Jet/Access back-end file. The form is set for "tab moves to next field, wrap-around" as opposed to "tab skips to next record after last field of current form". Users have to use a COMMIT button to save data, a CANCEL button to undo form changes. If you see the COMMIT button, you can never close the form because CLOSE vanishes - but you can CANCEL changes and CLOSE becomes available again.
I have the form trapped to a fare-thee-well to audit log or otherwise protect my users from their clumsiness and other mistakes. I also have update events to audit-log when someone does a COMMIT or tries to do some other action. I thought I had solved the problem of detecting changes in a field. However, this time I've found a case that has me scratching my head.
The problem came to light when a user inadvertantly entered a stray space character at the end of the existing text in a particular text box as described above. I'm really not worried about the sequence of keystrokes and mouse clicks that got the user to that point. I'm worried about the characteristics of that point.
What happens is that the form appears to be dirty (Me.Dirty = True if you use Debug.Print in the immediate window). But I manually contrived the case where the only difference was that I added a space to the tail end of a text field. When I did that, my internal auditing system compared .Value to .OldValue and didn't log anything - because the .Value and .OldValue were the same. Well, that's crazy because I know I added the spaces, and besides, the form's Dirty flag went TRUE on tabbing out of that field. So I know for a fact it saw the changes. But in the Locals window, the .Value and .OldValue strings were exactly the same. In other words, the string content and length BOTH matched. The locals window showed the .Value and .OldValue as quoted strings, neither having spaces at the end of the stuff inside of the quotes.
Now, what is confusing the issue is that the code acts like things are now dirty and the form's Dirty flag agrees. When I try to close the form, the BeforeUpdate event fires, implying that it thinks the form has changed. But in the only field I actually touched, the .Value and .OldValue are NOT different. Further, when the particular text box is still in focus, the .Text property agrees with (both) the .Value and .OldValue contents, including that it somehow lost the trailing spaces.
I try to close the form and it fires the BeforeUpdate event, but it is supposed to Cancel the close event in that case - but it doesn't. It lets me do the close because it somehow realizes that the form really wasn't dirty.
If I type a printing character in that field, even just a period or any other punctuation mark, it does what I expect it would do. In other words, the form really IS dirty and the trapping that I do prevents me from closing the form until I commit or cancel the change. So in normal use, the code works exactly as expected. But trailing spaces confuse the hell out of it.
Has anyone seen this kind of behavior before? It seems that Access makes the form DIRTY first, but then realizes that adding spaces at the end of the text box really didn't change anything so it sort of "calls off" that change. By that time, it is too late and the form is still dirty - but you can't tell what was changed by comparing old and new values.
Therefore, I repeat... :banghead:
OK, now that we have that out of the way, my question is really whether anyone has ever seen this before.
Ac2007 database. My form has a bound text-box to a text-type underlying field in a Dynaset query to a Jet/Access back-end file. The form is set for "tab moves to next field, wrap-around" as opposed to "tab skips to next record after last field of current form". Users have to use a COMMIT button to save data, a CANCEL button to undo form changes. If you see the COMMIT button, you can never close the form because CLOSE vanishes - but you can CANCEL changes and CLOSE becomes available again.
I have the form trapped to a fare-thee-well to audit log or otherwise protect my users from their clumsiness and other mistakes. I also have update events to audit-log when someone does a COMMIT or tries to do some other action. I thought I had solved the problem of detecting changes in a field. However, this time I've found a case that has me scratching my head.
The problem came to light when a user inadvertantly entered a stray space character at the end of the existing text in a particular text box as described above. I'm really not worried about the sequence of keystrokes and mouse clicks that got the user to that point. I'm worried about the characteristics of that point.
What happens is that the form appears to be dirty (Me.Dirty = True if you use Debug.Print in the immediate window). But I manually contrived the case where the only difference was that I added a space to the tail end of a text field. When I did that, my internal auditing system compared .Value to .OldValue and didn't log anything - because the .Value and .OldValue were the same. Well, that's crazy because I know I added the spaces, and besides, the form's Dirty flag went TRUE on tabbing out of that field. So I know for a fact it saw the changes. But in the Locals window, the .Value and .OldValue strings were exactly the same. In other words, the string content and length BOTH matched. The locals window showed the .Value and .OldValue as quoted strings, neither having spaces at the end of the stuff inside of the quotes.
Now, what is confusing the issue is that the code acts like things are now dirty and the form's Dirty flag agrees. When I try to close the form, the BeforeUpdate event fires, implying that it thinks the form has changed. But in the only field I actually touched, the .Value and .OldValue are NOT different. Further, when the particular text box is still in focus, the .Text property agrees with (both) the .Value and .OldValue contents, including that it somehow lost the trailing spaces.
I try to close the form and it fires the BeforeUpdate event, but it is supposed to Cancel the close event in that case - but it doesn't. It lets me do the close because it somehow realizes that the form really wasn't dirty.
If I type a printing character in that field, even just a period or any other punctuation mark, it does what I expect it would do. In other words, the form really IS dirty and the trapping that I do prevents me from closing the form until I commit or cancel the change. So in normal use, the code works exactly as expected. But trailing spaces confuse the hell out of it.
Has anyone seen this kind of behavior before? It seems that Access makes the form DIRTY first, but then realizes that adding spaces at the end of the text box really didn't change anything so it sort of "calls off" that change. By that time, it is too late and the form is still dirty - but you can't tell what was changed by comparing old and new values.
Therefore, I repeat... :banghead: