Form key events

G

Gary D.

Help - I'm getting in a muddle!

In Access2003, I have a popup modal form with the following:

one unbound text box into which is typed a security code with no events coded
one command button "btn_CloseForm_Click" with just the OnClick event coded
(and another command button that is not relevant to the current problem)

Within the "btn_CloseForm_Click" event a sub procedure (let's call it "X") is
called that performs some simple processing, after which control passes back
to "btn_CloseForm_Click" and then a "DoCmd.Close acForm, strCurrentForm.Name"
command is issued to close the form.

It is important to mention that procedure "X" needs to be called twice, once
for the first entry of the security code and then later on a second time for
re-entry and verification of the security code. The second call happens at a
different stage within the application but using this same form.

Here is the problem . . .

A present, when using the keyboard, when a user types a value into the text
box and presses the enter key, the cursor moves to the next tab stop, which is
the command button and the user must then hit the enter key again to trigger
the "btn_CloseForm_Click" event. That is working just fine.

Ideally I would like the keyboard behaviour to operate differently, such that
after a user types a value into the text box and presses the enter key, I can
capture that sequence of events and invoke procedure "X" (once only) and then
close the form, so the user doesn't have to hit the enter key again once the
cursor has moved onto the command button.

However, procedure "X" gets called twice (because of the way Access events
work?) and this is causing my coding to work differently from intended.

I appreciate that this description probably isn't very clear, but hope it
makes some sense.

So, how can I achieve my intended keyboard behaviour?
 
D

Douglas J Steele

You can change what the Enter key does on the Keyboard tab under Tools |
Options, but that would affect its behaviour on all forms.

You could also put code in the text box's AfterUpdate event to capture the
fact the user's left the text box after updating it.

There's also a EnterKeyBehavior property for text boxes, which is intended
to allow you to insert carriage returns into text. You could look in text
box's KeyPress event and trap the Enter key that way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top