I have defined a procedure under the click event of the button as follows.

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        'Validate Department
        If cmbDepartment.SelectedItem = Nothing Then
            MsgBox("Please select a department", MsgBoxStyle.Information, "Notification")
            cmbDepartment.Focus()
            Exit Sub
        End If
End Sub

I want to call this procedure when press on the enter key


Private Sub txtSearchValue_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSearchValue.KeyPress
If Asc(e.KeyChar) = 13 Then

MsgBox("Run the btnSearch click event")


End If
End sub


Can anyone suggest me a way to do this???????
Would be a great help

Please use code tags in the future

<- Remove the spaces and it will work
code here

To answer your question you should move the functionality to another method instead of calling the button's click event, but:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Button2_Click(sender, New System.EventArgs())
	End Sub

	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		MessageBox.Show("I called button2 from button1")
	End Sub

Thank you very much.
Awesome. Working exactly the way I want.
Thanks again

That was cool.. it works but when i call button click event
it does not do all things on the button1 event. for example

button1_click
msgbox "Boom"
Call loadmyData 'this thing didnt fire

button2_click
button1_click(sender, new system.eventargs())

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.