TabIndex problem

Slider

Member
Joined
Jun 11, 2009
Messages
22
Programming Experience
Beginner
Hi

I am writing a simple application which has two text boxes for user input (textbox1 and textbox2). Textbox1 has tabindex set to 1, textbox2 has tabindex set to 2. There is also a label which for some reason is set to 3. Obviously only want the tab to work between the text boxes. Does setting the label tabindex to 0 disable the tabindex to the label?

The application writes the values from the text boxes once the user leaves textbox 2. This is where the problem starts.......

If after leaving textbox2 by using the mouse to re-select textbox1, the programme works and writes the values into the access database. However, if I use the tab to leave textbox2 the programme crashes on the "command.ExecuteNonQuery" (Field 'Table1.Barcode1' cannot be a zero length strength). Using the debug stepinto routine it appears to be running the textbox2.leave event again. Below is the code from the textbox2.leave event:-

Private Sub TextBox2_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Leave
' create a new oledb connection
Dim connection As OleDb.OleDbConnection = NewConnection()
' create a new command objet
Dim command As OleDb.OleDbCommand = connection.CreateCommand
command.CommandText = "INSERT INTO Table1(Barcode1, Barcode2) " & _
"VALUES('" & Me.TextBox1.Text & "', " & _
"'" & Me.TextBox2.Text & "')"
connection.Open()
command.ExecuteNonQuery()
connection.Close()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()

End Sub


Any ideas?

Thank you in advance.
 
How about if you move your INSERT code to a save button rather than having it execute on leaving textbox2?

Second of all, I think that would solve the immediate problem.

First of all, and most importantly, it would give the user an opportunity to ensure they have the right things in both textboxes before saving it back to their database.
 
Label controls do hold a TabIndex value although it will be skipped right over when actually using the tab control. If your label has a tabindex of 3, after tabbing from your textbox2 it should skip over the label and go to the next lowest tabindex of a control that can receive focus.
 
How about if you move your INSERT code to a save button rather than having it execute on leaving textbox2?

Second of all, I think that would solve the immediate problem.

First of all, and most importantly, it would give the user an opportunity to ensure they have the right things in both textboxes before saving it back to their database.

It's going to be used with a barcode scanner. Needs to be a quick process, do not want the user having to click a save button after each scan of the second barcode.
 
For barcode inserts, I use the textboxes keypress event and test for the enter key that the barcode will include and use that to call my sub to run my query
 
For barcode inserts, I use the textboxes keypress event and test for the enter key that the barcode will include and use that to call my sub to run my query

Thank you. I have actually used the keydown event and it seems to be working a treat.

Cheers
 
Back
Top