Enter same as click on Command

I have several text boxes that the user fills out and then clicks on a command button to store the data.  I would like to also have the enter key also function the same as the command button.  How can I do this?
donb1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

setiawanCommented:
donb1,
During design-time, On the Command Button, set Default property to true

  danny
0
donb1Author Commented:
setiawan
  Your answer puts the focus on the command button, but as soon as someone starts filling out the form, the focus changes and pressing the enter key does nothing!
0
amebaCommented:
or do it at run time
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

amebaCommented:
It won't work if focus is on RichTextBox.
0
VbmasterCommented:
Put this code in the keydown event of the textboxes..

If (KeyCode = vbKeyReturn) Then
  Call Command1_Click
End If

Or something like that depending on what the command button name is.
0
amebaCommented:
Vbmaster's code is not practical. You better retry what setiawan said.
0
VbmasterCommented:
ameba.. not practical because.. ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
donb1Author Commented:
Vbmaster
  I get a variable undefined (KeyCode) when I put the code in the text box.  If I define the variable, nothing happens.

  I also have some data boxes that are list boxes.

ameba
  setiawan's answer puts the focus on the command button, but as soon as someone starts filling out the form, the focus changes and pressing the enter key does nothing!
0
amebaCommented:
You'll have to put that code at many places: many textbox names, option buttons, checkboxes...
Also, default button should look like it is default - you know, border...
0
amebaCommented:
Well, default won't work on RichTextBox or when focus is on another button. It works for listboxes.

Put some code to see if it executes:

Private Sub Command1_Click()
    Beep
End Sub
0
donb1Author Commented:
Vbmaster
   Sorry, your answer does work.  I made an error the first time I tried it.

Thanks
0
VbmasterCommented:
ameba: about putting the code "at many places: many textbox names, option buttons, checkboxes".. ever heard of control arrays? ;)
0
amebaCommented:
Ah, yes, with control arrays it will be simpler than setting one property ...
0
VbmasterCommented:
I guess it's no point arguing a point with somebody that thinks that adding pointers are worse than copying a whole structure of data (old question here on EE)  ;)

ah well, just for the hell of it.. setting one property.. a solution that only works "sometimes", nice solution
0
amebaCommented:
This is what I learned from others and measured myself. Also, I said *CAN BE*.

>.. a solution that only works "sometimes", nice solution
I agree, but I am not sure this is the case here.
0
amebaCommented:
Vbmaster wrote in other question:
>I do the swap with that numerical array instead of swapping the string values (slow as hell!).

If you look better into ShellSort routine, you'll see what is swapped - it's not strings, but pointers to strings - itemlen is only 6 bytes. So it's not that slow. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.