Pressing Enter rather than click with mouse

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been asked to create a database applciation in Access that does not
need the use of the mouse.
I have managed to get buttons a check boxes to allow a key press of alt-a,
alt-b etc by using the & at the start of the name but what I really want is
to be able to press enter when positioned on a field or button asnd for the
same action to occur as it would if I clicked it with the mouse.
When an Access message or error is displayed pressing enter is the same as
clicking ok, this is what I want ot achieve.
Can anyone advise how to do this?
 
You an set a buttons control's "default" property to "yes". (this setting is
found in the other tab). If you hit enter, then that button will behave as
if you just clicked on it with the mouse. You can only have one of these on
a screen.

Of course, if a button (any button) has the focus..then just hitting the
space bar will click the button.
 
Hi Albert
Thanks for the prompt response! I thought Canada was in 'sleep mode' at
this 'time zone time of day'!

Not quite the solution I was seeking, as hitting [enter] or [tab] already
defaults to a move to the next field, and either is totally acceptable.

What I _want_ to do is discourage people from using the mouse to navigate
to the next field, and if they do, to display a polite informative
message...!

So I need to know if there is a code I can use to trap if a user has clicked
the mouse to exit a field...

cheers
DubboPete
 
You don't even need the trick you employed. You can browse through all
conrtols on a form (including the command buttons) with the Tab key. When
you set focus on a command button, the Enter key will do what you want. A
checkbox can be toggled checked/unchecked with the spacebar. Acombo box can
be made to drop down with Alt+DownArrow (or you cold use its On Got Focus
event to have it automatically drop down). An listbox or option group
selection can be made/changed with the Up and Down arrows... What else?

HTH,
Nikos
 
Not quite the solution I was seeking, as hitting [enter] or [tab] already
defaults to a move to the next field, and either is totally acceptable.

Ok...but the "default" value is a good thing to know...this is especially
handy for custom dialog boxes etc, or prompting screens that you use to ask
the user questions. So, not what you are looking for..but still good access
feature to know about.
but what I really want is
to be able to press enter when positioned on a field or button asnd for the
same action to occur as it would if I clicked it with the mouse.

You can thus use the keydown event on a field, and trap if the user hits
enter. (see the keydown event for a control). When the user hits the enter
key, you then simply call the same code that clicking on the control would
have called (ie: you simply have both the on-click event, and the EnterKey
call the same peice of code).
What I _want_ to do is discourage people from using the mouse to
navigate to the next field, and if they do, to display a polite
informative message...!

Ah..the above is a VERY different question. As you can see by giving you a
solution to the first question...it does NOT give you a solution to your
above problem!
So I need to know if there is a code I can use to trap if a user has
clicked the mouse to exit a field...

Hum....yes, you can do this. I would declare a module level string var like:
dim strLastContorlEnterKey as string

Now, set the forms keypreview = yes, and in the forms global keydown event,
you can go:

on error resume next
if KeyPress = vbEnter then
strLastContorlEnterKey = screeen.ActiveContorl.name
endif

Now, for any controls on-enter event, you can check what the last control
was that the user hit the enter key in.

if strLastConotrlEnterKey <> screen.PreviousContorl.name then
msgbox "hey, you did not use the enter key to get here!!"
end if
 

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

Back
Top