Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

executing a macro when the Enter key is pressed in a textbox

Status
Not open for further replies.

ScubaStevo

Programmer
Joined
May 4, 2002
Messages
132
Location
AU
I want to execute a macro when the user presses the enter key rather than needing clicking on an OK button or pressing the enter key several times to get to the OK button and pressing enter on that.

The OnChange and OnExit events arent suitable for this, is there a way I can use the OnKeyPress to return the enter when pressed key and execute the macro then?

Thanks

Steve
 
Use the Form's KeyDown event to trap for the Enter Key being pressed.

You also need to set the form's Key Preview event to YES for this to work correctly.

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
        'Do Whatever
    Else
        'Do Something Else
    End If
End Sub

HTH
Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top