Default commandbutton

×

×לי

Hi,

I have userform with few textboxes and few commandbuttons. my question is
how to make that after i will finish entering data to one of the textboxs and
click Enter specific commandbutton will be executed.

Thanks in advance
Eli
 
R

Rick Rothstein \(MVP - VB\)

I have userform with few textboxes and few commandbuttons. my question is
how to make that after i will finish entering data to one of the textboxs
and
click Enter specific commandbutton will be executed.

Set the Default property to True for the CommandButton whose Click event
code you want to execute whenever the Enter key is pressed. If you need to
know which control had focus when the Enter key was pressed, set up a
form-wide global variable in the form window's (General)(Declarations)
section and Set this variable to the control object in each control's Enter
event. Maybe something like this, as a starting framework, for example...

Dim LastControl As Control

Private Sub CommandButton1_Click()
Debug.Print LastControl.Name
End Sub

Private Sub TextBox1_Enter()
Set LastControl = TextBox1
End Sub

Private Sub TextBox2_Enter()
Set LastControl = TextBox2
End Sub

Rick
 

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