I am trying to detect a field in a textbox (bound to a table) being changed to enable a save or cancel button. Can someone tell me why this syntax does not work, thanks.
On Change event
If Me!NName <> Me!NName.OldValue Then
........
No, it just goes passed. The other thing thats really driving me up the wall, and I never had problems like this in Access97, is returning focus to a control when its empty. I have tried all event properties ie AfterUpdate, On Exit etc, and it never returns to the control.
If IsNull(Me.NName) = False Then
Me.NName.SetFocus
Me.NName.SelStart = Len(Trim(Me.NName)) + 1
Else
Me.NName.SetFocus
Exit Sub
End If
I have also tried If Trim(Me.NName) = "" Then
But nothing works. Hope someone else can tell me why, as I am wasting so much time. Thanks
Many thanks PHV, that fixes it. Another little change in Access to help spend a few hours enjoyment. I had spent hours debugging the code and watching it go to setfocus without doing it. Have a star and thanks yet again.
PHVs suggestion, is the fastest I've encountered on several tests, though for form controls fractions of milliseconds aren't really that interesting. PHVs suggestion also has one more advantage - in some events, like for instance the on change event of controls, there's a possibility of the control only containing a space, which PHVs suggestion traps for, and NZ doesn't.
However, in the on change event of controls, testing the .Value property, as is done here (.Value is the default property of controls), is perhaps not the most interesting property, as this doesn't change until whatever changes are performed are saved to the control, perhaps test then .Text property of the control in stead, or use another event, for instance the After Update event of the control.
Excellent points, RoyVidar. One of my dirty little secrets is not knowing the difference between .text and .value for textboxes. Sounds like .text is real-time contents and .value is after last update (due to lostfocus, etc)...?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.