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

Recommended Answers

All 3 Replies

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

Your solution works! Thank you, Reena!
~ Sheryl

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.