My form's KeyPreview is set to True. I want to allow my users to use the Enter Key instead of just the Tab key. I have the following code in my form's KeyPress event:

Private Sub frmDesigner_KeyPress(ByVal sender As Object, ByVal e As   System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If e.KeyChar = vbkeyreturn Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

It doesn't like vbkeyreturn, which I used in Visual Basic 6.0. I think I must be close to having it right. Your help is appreciated!

~ Sheryl

Hi,

Private Sub frmDesigner_KeyPress(ByVal sender As Object, ByVal e As   System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If Asc(e.KeyChar) = Keys.Enter Then
            SendKeys.Send("{TAB}")
        End If
End Sub

Edited 3 Years Ago by mike_2000_17: Fixed formatting

My form's KeyPreview is set to True. I want to allow my users to use the Enter Key instead of just the Tab key. I have the following code in my form's KeyPress event:

Private Sub frmDesigner_KeyPress(ByVal sender As Object, ByVal e As   System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If e.KeyChar = vbkeyreturn Then
            SendKeys.Send("{TAB}")
        End If
    End Sub

It doesn't like vbkeyreturn, which I used in Visual Basic 6.0. I think I must be close to having it right. Your help is appreciated!

~ Sheryl

just declare your vbkeyreturn, that does it

Dim vbkeyreturn as char=chr(13)

This question has already been answered. Start a new discussion instead.