By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 832 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

Problem with TAB

P: 56
I am working with VB6 and Access.
I have a textbox where the user enters values and presses either enter or tab key which triggers a keypress event and fetches corresponding values from the database. the keypress event needs to check if enter key or tab key is pressed. for enter key it is working but for tab key it isnt. Is it fine to write a keypress event for checking that TAB key was pressed???or lostfocus event has to be used???? and i guess ascii value of tab is 9. right??
Feb 3 '08 #1
Share this Question
Share on Google+
5 Replies


P: 68
I am working with VB6 and Access.
I have a textbox where the user enters values and presses either enter or tab key which triggers a keypress event and fetches corresponding values from the database. the keypress event needs to check if enter key or tab key is pressed. for enter key it is working but for tab key it isnt. Is it fine to write a keypress event for checking that TAB key was pressed???or lostfocus event has to be used???? and i guess ascii value of tab is 9. right??
u can try it in KeyDown Event. Yes, both Ascii & KeyCode value of TAB is 9.
Feb 3 '08 #2

P: 56
u can try it in KeyDown Event. Yes, both Ascii & KeyCode value of TAB is 9.


But the problem still persists even with keydown event....ascii values for all the keys are considered but when i press tab, the focus shifts to the next control. but i want certain code to execute when tab is pressed. how to achieve that???
Feb 3 '08 #3

P: 56
I tried the following code for my requirement but i am getting an error when ENTER key is pressed.
Run-time error: 400
form already open. cannot open it modally.

What should be done???


Private Sub txtProd_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
txtProd_LostFocus
End If

End Sub

Private Sub txtProd_LostFocus()

If txtProd.Text <> "" Then
If IsNumeric(txtProd.Text) = True Then
MsgBox "if"
var = lstSrno.ListCount + 1
Call Connection
Set rs = New ADODB.Recordset
rs.Open "Select * from Products where Prod_Code=" & Val(txtProd.Text) & "", con, 3, 3
lstSrno.AddItem (var)
lstProd.AddItem (txtProd.Text)
lstDescrptn.AddItem (rs!Prod_Name)
lstStax.AddItem (rs!ST)
con.Close
txtProd.Locked = True
txtQty.SetFocus
Else
MsgBox "else"
frmValidNo.Show vbModal
With txtProd
.Text = ""
.SetFocus
End With
End If
Else
frmValid.Show vbModal
With txtProd
.Text = ""
.SetFocus
End With
End If

End Sub
Feb 3 '08 #4

P: 68
I tried the following code for my requirement but i am getting an error when ENTER key is pressed.
Run-time error: 400
form already open. cannot open it modally.

What should be done???


Private Sub txtProd_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
txtProd_LostFocus
End If

End Sub

Private Sub txtProd_LostFocus()

If txtProd.Text <> "" Then
If IsNumeric(txtProd.Text) = True Then
MsgBox "if"
var = lstSrno.ListCount + 1
Call Connection
Set rs = New ADODB.Recordset
rs.Open "Select * from Products where Prod_Code=" & Val(txtProd.Text) & "", con, 3, 3
lstSrno.AddItem (var)
lstProd.AddItem (txtProd.Text)
lstDescrptn.AddItem (rs!Prod_Name)
lstStax.AddItem (rs!ST)
con.Close
txtProd.Locked = True
txtQty.SetFocus
Else
MsgBox "else"
frmValidNo.Show vbModal
With txtProd
.Text = ""
.SetFocus
End With
End If
Else
frmValid.Show vbModal
With txtProd
.Text = ""
.SetFocus
End With
End If

End Sub

See this code:

Private Sub Form_Load()
Text1.TabStop = False
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 9 Then
MsgBox "TAB Key is Pressed"
End If
End Sub

I think, u can easily understand, wht have to do. Set the TabStop Property of the TextBox txtProd to False. Then u can get ur result.

If u r succeed, reply me.
Get Better.

Regards,
shuvo2k6
Feb 3 '08 #5

Expert 5K+
P: 8,434
A couple of thoughts on this thread...
  • Why do you need to reopen a form that's already open? Is it the same form you're already in?
  • TabStop determines whether the Tab key will move the focus to the control, not away from it.
  • Since Tab key moves focus between controls, it seems unlikely to be seen in the KeyDown event procedure for the control. But perhaps if you set the form's KeyPreview property you could detect it at the form level?
Feb 4 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.