From: Salad on
I'm coming from a background with Access. If I have a textbox on a
from, Access has a BeforeUpdate or AfterUpdate event that fires if one
hits the tab or Enter key.

So I wondered how one fires an event when one hits the Enter key. It
appears I have to check for the key press. I entered the following code
for a textbox and it beeps at me.
Private Sub TextBox1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles TextBox1.KeyDown
If e.KeyCode = 13 Then
Call GoToLink()
End If
End Sub

It doesn't matter if I comment out
'Call GoToLink()
I still get a beep. From my testing, it appears the beep is produed
when the code hits the End Sub.

How can I remove the Beep?

Also, is there a better way to validate my textbox when I hit the enter key?
From: Tom Dacon on

"Salad" <salad(a)oilandvinegar.com> wrote in message
news:sdmdnYZVJJ35y1rWnZ2dnUVZ_tmdnZ2d(a)earthlink.com...
> I'm coming from a background with Access. If I have a textbox on a from,
> Access has a BeforeUpdate or AfterUpdate event that fires if one hits the
> tab or Enter key.
>
> So I wondered how one fires an event when one hits the Enter key. It
> appears I have to check for the key press. I entered the following code
> for a textbox and it beeps at me.
> Private Sub TextBox1_KeyDown(ByVal sender As Object, _
> ByVal e As System.Windows.Forms.KeyEventArgs) _
> Handles TextBox1.KeyDown
> If e.KeyCode = 13 Then
> Call GoToLink()
> End If
> End Sub
>
> It doesn't matter if I comment out
> 'Call GoToLink()
> I still get a beep. From my testing, it appears the beep is produed when
> the code hits the End Sub.
>
> How can I remove the Beep?
>
> Also, is there a better way to validate my textbox when I hit the enter
> key?

Take a look at the KeyEventArgs object and see if it has a Handled property.
If so, set it to True at the end of the event handler and it'll probably
suppress the beep. It used to work this way in VB6 anyway.

Tom Dacon
Dacon Software Consulting


From: Armin Zingler on
Am 15.04.2010 20:09, schrieb Salad:
> I'm coming from a background with Access. If I have a textbox on a
> from, Access has a BeforeUpdate or AfterUpdate event that fires if one
> hits the tab or Enter key.
>
> So I wondered how one fires an event when one hits the Enter key. It
> appears I have to check for the key press. I entered the following code
> for a textbox and it beeps at me.
> Private Sub TextBox1_KeyDown(ByVal sender As Object, _
> ByVal e As System.Windows.Forms.KeyEventArgs) _
> Handles TextBox1.KeyDown
> If e.KeyCode = 13 Then
> Call GoToLink()
> End If
> End Sub
>
> It doesn't matter if I comment out
> 'Call GoToLink()
> I still get a beep. From my testing, it appears the beep is produed
> when the code hits the End Sub.

It appears whenever a char is entered that is not accepted by the textbox.
This means you could also press Ctrl+A (Chr(1)), etc to produce it.

> How can I remove the Beep?

Private Sub TextBox1_KeyPress( _
ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox1.KeyPress

If e.KeyChar = ControlChars.Cr Then
e.Handled = True
End If
End Sub

> Also, is there a better way to validate my textbox when I hit the enter key?

I don't know.


--
Armin
From: Salad on
Armin Zingler wrote:
> Am 15.04.2010 20:09, schrieb Salad:
>
>>How can I remove the Beep?
>
>
> Private Sub TextBox1_KeyPress( _
> ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
> Handles TextBox1.KeyPress
>
> If e.KeyChar = ControlChars.Cr Then
> e.Handled = True
> End If
> End Sub
>

Thanks for your reply.

I created a new project/form. Added 2 textboxes. No code. If I enter
data into 1 textbox and hit the tab key it silently moves to the next
box. If I forego the enter key it beeps at me and sits in the same field.

I added your code to Textbox1 (there's no keyChar) so I used
If e.KeyCode = Keys.Enter Then
e.Handled = True
End If
instead. It still beeps. I'm wondering if there's a global form
setting to turning Beeps off. Or a way to hit an enter key on a field
and not have it beep at the user. Also, hit the enter key and move to
the next input field like days of old. I have this crazy image of
people using vb.net apps worldwide and the beep sound fills the air like
flocks of birds. Attack of the Annoying Beeps! Maybe the beeps are
used as negative reinforcement to train people to use the Tab key to
move to another field instead of the Enter key.
From: Armin Zingler on
Am 16.04.2010 02:12, schrieb Salad:
> It still beeps.

Look at my code. It handles the Keypress event, not the Keydown event.


--
Armin