Hello,
I am working on a small project where I need to validate that text box has an entry before going to next field. (Note: Validating event does not work here because they have the option to click a different radio button selection.) I have the Enter key working but I cannot seem to get the code to recognize the Tab key. Can you please take a look at the following code and let me know what I am doing wrong? I appreciate any guidance you can provide. THANKS!
Private Sub txtEntry_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtEntry.KeyDown
If e.KeyCode = Keys.Enter Then
'User must enter a value in Entry box if Other or Online is checked
If txtEntry.Text = "" Then
If Me.radOther.Checked Then
MessageBox.Show("Please enter the source of the request before continuing.", "Information Required")
Me.txtEntry.Focus()
ElseIf Me.radOnline.Checked Then
MessageBox.Show("Please enter the RequestID before continuing.", "Information Required")
Me.txtEntry.Focus()
End If
Else
Me.txtReqDate.Focus()
End If
ElseIf e.KeyCode = Keys.Tab Then
If Me.radOther.Checked Then
MessageBox.Show("Please enter the source of the request before continuing.", "Information Required")
Me.txtEntry.Focus()
ElseIf Me.radOnline.Checked Then
MessageBox.Show("Please enter the RequestID before continuing.", "Information Required")
Me.txtEntry.Focus()
End If
End If
End Sub
I am working on a small project where I need to validate that text box has an entry before going to next field. (Note: Validating event does not work here because they have the option to click a different radio button selection.) I have the Enter key working but I cannot seem to get the code to recognize the Tab key. Can you please take a look at the following code and let me know what I am doing wrong? I appreciate any guidance you can provide. THANKS!
Private Sub txtEntry_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtEntry.KeyDown
If e.KeyCode = Keys.Enter Then
'User must enter a value in Entry box if Other or Online is checked
If txtEntry.Text = "" Then
If Me.radOther.Checked Then
MessageBox.Show("Please enter the source of the request before continuing.", "Information Required")
Me.txtEntry.Focus()
ElseIf Me.radOnline.Checked Then
MessageBox.Show("Please enter the RequestID before continuing.", "Information Required")
Me.txtEntry.Focus()
End If
Else
Me.txtReqDate.Focus()
End If
ElseIf e.KeyCode = Keys.Tab Then
If Me.radOther.Checked Then
MessageBox.Show("Please enter the source of the request before continuing.", "Information Required")
Me.txtEntry.Focus()
ElseIf Me.radOnline.Checked Then
MessageBox.Show("Please enter the RequestID before continuing.", "Information Required")
Me.txtEntry.Focus()
End If
End If
End Sub