Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change event incorrect? 5

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
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
........
 
this syntax does not work
What happens ? Any error message ? Unexpected behaviour ? Computer crash ? ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
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
 
it never returns to the control
In the Exit event procedure of NName:
If Trim(Me!NName & "") = "" Then Cancel = True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
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.
 
A tweak to make it even better(faster execution and less typing): use the Nz() function to handle the "Null" problem. I love using Nz.

Change: If Trim(Me!NName & "") = "" Then Cancel = True
To: If Nz(Me!NName,"")="" then Cancel = True

Nz will return "" if Nname is Null

Aaron
 
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.

Roy-Vidar
 
Agree with [blue]RoyVidar![/blue]

Its the uncomitted data in the [blue]Text[/blue] property that is of interest in the [blue]Change[/blue] event . . .

Calvin.gif
See Ya! . . . . . .
 
Thanks guys, just seen this pop back in the frame. Regards
 
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)...?
 
Be aware that the Text property is available only when the control has focus ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top