key down usage on form

S

seeker

I have noticed that forms have a key down event just like text boxes yet when
i put code in the event it does not work. for instance

if keycode = vbkeyreturn then
docmd.close "frmMyForm"
end if

does not close the form when I am anywhere on the form. If I put the same
code in a textbox and if I am in the textbox and hit enter then the form
closes. How does key down initiate on forms.
 
T

Tom van Stiphout

On Tue, 6 Oct 2009 20:04:01 -0700, seeker

From the help file:
the object with the focus receives all keystrokes. A form can have the
focus only if it has no controls or all its visible controls are
disabled. A form will also receive all keyboard events, even those
that occur for controls, if you set the KeyPreview property of the
form to Yes.

-Tom.
Microsoft Access MVP
 

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