View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Default commandbutton

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