Using the keystroke

crowegreg

Registered User.
Local time
Today, 09:55
Joined
Feb 28, 2011
Messages
108
A requirement of my current db is that when the user reaches the last text box on the form, they need to press the enter key. How do I code it so after they've entered some data, if they press any key other than the return key, it stops all the other events within this text box and it resets the focus to this text box.
 
This "requirement" stems from where exactly? And what does pressing the enter key do?

Because user-interface-wise it does not make much sense to me. What if the user discovers a typo or wrong input in one of the other controls? It is not common practice to trap a user like that.
 
It what the customer desires. I explained the pitfalls, but I need to try and deliver what they've asked. If I get it working like they've asked, they probably won't like it. At least it's a good learning experience for me.
 
I guess you could do it with a module level flag.
You set the flag by declaring a boolean variable at the top of the form's module, i.e.:
dim blnFlag as boolean
then you would enter the phrase
If blnFlag = False Then Cancel = True
in the textbox's "beforeupdate" event. This makes the user unable to move out of the textbox as long as the flag is equal to false (default value).

finally, you should write something like
If KeyCode <> 13 Then
blnFlag = False
Else
blnFlag = True
End If

to textbox's "on key up" event. this makes the return key the only way to set the flag to true.

I would suggest you try this approach. and play around with the ESC key btw.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom